How to bind a generated fancybox to a button? #110
-
Hi! Is it possible to do something like this code below but with Fancybox.bind? let htmlContent = '<div id=\"container\">Hello fancybox</div>';
Fancybox.show([{ src: htmlContent, type: 'html' }]); In the old jQuery version it would look something like this: $('#button-id').fancybox({
content: htmlContent
}); |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Hi, That old syntax looks confusing, doesn't it? Therefore, it is no longer supported and a clearer syntax is proposed, example: let htmlContent = '<div id="container">Hello fancybox</div>';
document.getElementById("button-id").addEventListener("click", () => {
Fancybox.show([{ src: htmlContent, type: "html" }]);
}); |
Beta Was this translation helpful? Give feedback.
-
Use |
Beta Was this translation helpful? Give feedback.
Use
bind()
to attach default click handler to the selector. Here - https://github.com/fancyapps/ui/blob/main/src/Fancybox/Fancybox.js#L1496 - is the default selector. When you callbind()
multiple times with the same selector, you are just overwriting options (for that selector).btw, information about selectors and options is stored inside
Fancybox.openers
Map object.