I would like to launch a Fancybox (e.g. Fancybox's version of a modal or light box) on page load. I could bind it to a hidden anchor tag and fire the click event of that anchor tag via JavaScript, but I would rather just launch the Fancybox directly and avoid the extra anchor tag.
jQuery(document). ready(function($) { $('button'). on('click', function() { $. fancybox(); }); });
fancyBox is a tool that offers a nice and elegant way to add zooming functionality for images, html content and multi-media on your webpages.
You can close it with $. fancybox. close() .
Fancybox currently does not directly support a way to automatically launch. The work around I was able to get working is creating a hidden anchor tag and triggering it's click event. Make sure your call to trigger the click event is included after the jQuery and Fancybox JS files are included. The code I used is as follows:
This sample script is embedded directly in the HTML, but it could also be included in a JS file.
<script type="text/javascript"> $(document).ready(function() { $("#hidden_link").fancybox().trigger('click'); }); </script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With