如何使用ShadowBox在页面加载时打开内联div?

Kul*_*vis 4 jquery shadowbox

我想在页面加载时打开div.我粘贴的代码在ShadowBox库中给出了一个javascript错误:'container is undefined'

我怎样才能做到这一点?

$(document).ready(function () {

    Shadowbox.init({ skipSetup: true }); 
    Shadowbox.open({
        content: '#surveyDialog',
        player: 'inline',
        height: 450,
        width: 500
    });
});


<div id="surveyDialog" class="dialogWindowWrapper">
    <h2>Hello!</h2>
</div>
Run Code Online (Sandbox Code Playgroud)

art*_*ics 5

该错误是由于Shadowbox在未准备好时打开了某些内容.

对于头部,请使用:

<script type="text/javascript">

    Shadowbox.init({
        skipSetup: true
    });

    window.onload = function() {

        Shadowbox.open({
            content: '#surveyDialog',
            player: 'inline',
            height: 450,
            width: 500
        });

    };

</script>
Run Code Online (Sandbox Code Playgroud)

对于body部分,请使用:

<div id="surveyDialog" class="dialogWindowWrapper" style="display:none">
    <h2 style="color:#ffffff;">Hello!</h2>
</div>
Run Code Online (Sandbox Code Playgroud)

对于准备使用太极拳的例子,请访问源页面在GitHub上这里.

编辑:如果您想Shadowbox.open在页面加载后访问,请查看此处显示的修改后的脚本:

<script type="text/javascript">

    Shadowbox.init({
        skipSetup: true
    });


    function survery01(){
        Shadowbox.open({
            content: '#surveyDialog',
            player: 'inline',
            height: 450,
            width: 500
        });
    }

    window.onload = function() {

        survery01();

    };

</script>
Run Code Online (Sandbox Code Playgroud)

现在它Shadowbox.open位于命名函数中,您可以在需要时调用它(例如,使用onclick属性).