jQuery 如何在页面加载时打开一个巨大的弹出窗口?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18726419/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to open a magnific popup on page load?
提问by Bruno Gomes
I'm using Magnific Popupand I would like to have a video come up as soon as the page loads in a popup.
我正在使用Magnific 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.
我环顾四周寻找解决方案,但我没有设法让它发挥作用。
回答by bbone
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:
如果您使用的是 jQuery,您可以只监听窗口加载事件,然后为您的 Magnific Popup 调用 open 方法,如下所示:
(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);
回答by Syndication
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.
我能够使用 jquery 的 setTimeout 函数获得定时模式工作,只需将 .magificpopup 包装在 settimeout 函数中即可设置延迟。将 5000(5 秒)的值更改为您想要的任何值。
See below:
见下文:
$(document).ready(function () {
setTimeout(function() {
if ($('#myModal').length) {
$.magnificPopup.open({
items: {
src: '#myModal'
},
type: 'inline'
});
}
}, 5000);
});