How to open a magnific popup on page load?

萝らか妹 提交于 2019-11-29 11:45:04

问题


I'm using Magnific Popup and I would like to have a video come up as soon as the page loads in a popup.

I got the plugin to work fine, but I have no idea on how to get it to pop up as soon as the page loads, without clicking on the thumbnail.

I looked around for a solution, but I did not manage to get it to work.


回答1:


If you're using jQuery you could just listen for the window load event and then call the open method for your Magnific Popup like so:

(function($) {
    $(window).load(function () {
        // retrieved this line of code from http://dimsemenov.com/plugins/magnific-popup/documentation.html#api
        $.magnificPopup.open({
            items: {
                src: 'someimage.jpg'
            },
            type: 'image'

          // You may add options here, they're exactly the same as for $.fn.magnificPopup call
          // Note that some settings that rely on click event (like disableOn or midClick) will not work here
        }, 0);
    });
})(jQuery);



回答2:


I was able to get a timed modal working using jquery's setTimeout function, Just wrap .magificpopup in the settimeout function to set a delay. Change the value of 5000 (5 seconds) to whatever value you want.

See below:

$(document).ready(function () {
setTimeout(function() {
 if ($('#myModal').length) {
   $.magnificPopup.open({
    items: {
        src: '#myModal' 
    },
    type: 'inline'
      });
   }
 }, 5000);
});


来源:https://stackoverflow.com/questions/18726419/how-to-open-a-magnific-popup-on-page-load

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!