fancybox - 我可以将参数传递给链接到工具栏中新自定义按钮的函数吗?

fancybox - Can I pass a parameter to the function linked to a new custom button in the toolbar?

我按照此处的说明在工具栏中创建了一个自定义按钮:

https://fancyapps.com/fancybox/3/docs/#faq-3

我想将图像 ID 传递给点击功能 - 我可以这样做吗?

谢谢!

你不需要传递任何东西。这是您可以从代码中的任何位置访问触发元素(例如,您单击以打开当前图像的 link)的方式:

$.fancybox.getInstance().current.opts.$orig

您可以向 link 添加一些属性(如 data-image-id),然后在需要时(从您的点击事件中)读取它。