javascript 如何在页面加载时加载 magnific popup modal

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20507900/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 18:38:48  来源:igfitidea点击:

how to load magnific popup modal on page load

javascriptjqueryonloadmagnific-popup

提问by marchemike

I'm trying to load my magnific popup modal on page load, however I can't quite understand the syntax in the documentation. How do I call the modal on page load?

我正在尝试在页面加载时加载我的 magnific popup modal,但是我不太明白文档中的语法。如何在页面加载时调用模态?

My HTML:

我的 HTML:

<div id="test-modal" class"white-popup-block mfp-hide">
    <h1>Modal Test</h1>
    <p>
    Test Some text.
    </p>
    <p>
    <a class="popup-modal-dismiss">Dismiss</a>
    </p>
</div>

My JS:

我的JS:

$(window).load(function(){

???? What code should I place???
});

I have already preloaded the script and css files, what do I type inside the JS to make it load the popup on load?

我已经预加载了脚本和 css 文件,我在 JS 中输入什么才能让它在加载时加载弹出窗口?

回答by Fabricio

Try this:

试试这个:

$.magnificPopup.open({
    items: {
        src: '<div id="test-modal" class="white-popup"><h1>Modal Test</h1><p>Test Some text.</p><p><a class="popup-modal-dismiss">Dismiss</a></p></div>',
        type:'inline'
    },
    modal: true
});

And the fiddle...

还有小提琴...

回答by Kareem JO

$.magnificPopup.open({items: {src: '#id-of-your-popup'},type: 'inline'}, 0);

回答by Rafael Antonio Torres

You can try this:

你可以试试这个:

    $.magnificPopup.open({
        items: {
            src: 'images/loading.gif',
            type:'image'
        },
        modal: true
    });