how to load magnific popup modal on page load

2019-07-06 17:15发布

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?

My 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:

$(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?

3条回答
Animai°情兽
2楼-- · 2019-07-06 17:37

You can try this:

    $.magnificPopup.open({
        items: {
            src: 'images/loading.gif',
            type:'image'
        },
        modal: true
    });
查看更多
劫难
3楼-- · 2019-07-06 17:50

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...

查看更多
聊天终结者
4楼-- · 2019-07-06 17:54
$.magnificPopup.open({items: {src: '#id-of-your-popup'},type: 'inline'}, 0);
查看更多
登录 后发表回答