如何在页面加载时自动打开prettyPhoto灯箱?

时间:2010-09-24 20:37:08

标签: jquery autoload

我是Jquery的新手,我找到了几个使用cookie和onload功能打开灯箱的例子。我正在使用与fancybox一起使用的cookie示例,但我一直在我的所有网站上使用prettyPhoto,并且真的不想更改为fancybox。我已经尝试了十几种不同的方法来实现这一点,但我没有运气。这是我的代码。任何帮助或建议都会很棒。

$(文件)。就绪(函数(){

// !!! SEE THIS PLEASE !!!
// delete this line to make the modal box load only ONCE
// if you let it set to 'false' it will show every time .. set it to 'true' and it will never show
$.cookie("modal", 'false')

/**
  *  MODAL BOX
  */
// if the requested cookie does not have the value I am looking for show the modal box
if($.cookie("modal") != 'true')
{
    alert("sometext");

var where =“http://images.motortrend.com/photo_gallery/112_0611_39z+2006_bugatti_veyron+interior.jpg”;   var title =“”;   var comment =“”;

function showLbox(){    $ .prettyPhoto.open(where,title,comment);   }         //在页面加载时显示模态框         //有关您可以在fancybox网站上找到的选项的更多信息

    // in the message is a link with the id "modal_close"
    // when you click on that link the modal will close and the cookie is set to "true"
    // path "/" means it's active for the entire root site.. if you set it to "/admin" will be active on the "admin" folder
    // expires in 7 days
    // "modal" is the name i gave the cookie.. you can name it anything you want
    $('#modal_close').live('click', function(e) {
        e.preventDefault();
        $.cookie("modal", "true", { path: '/', expires: 7 });


    });
}

});

1 个答案:

答案 0 :(得分:3)

在页面加载完成后,您必须调用S.prettyPhoto.open API函数。我把它放在$(document).ready(function()函数:

$(document).ready(function(){
            $(".gallery:first a[rel^='prettyPhoto']").prettyPhoto({animationSpeed:'fast',slideshow:10000});
            $(".gallery:gt(0) a[rel^='prettyPhoto']").prettyPhoto({animationSpeed:'fast',slideshow:10000});

            $("#custom_content a[rel^='prettyPhoto']:first").prettyPhoto({
                custom_markup: '<div id="map_canvas" style="width:260px; height:265px"></div>',
                changepicturecallback: function(){ initialize(); }
            });

            $("#custom_content a[rel^='prettyPhoto']:last").prettyPhoto({
                custom_markup: '<div id="bsap_1237859" class="bsarocks bsap_d49a0984d0f377271ccbf01a33f2b6d6" style="height:260px"></div><div id="bsap_1251710" class="bsarocks bsap_d49a0984d0f377271ccbf01a33f2b6d6"></div>',
                //changepicturecallback: function(){ _bsap.exec(); }

            });
            $.prettyPhoto.open('FMWM5.swf?width=544 &amp;height=399', '', 'Click anywhere to skip intro...');
            setTimeout("$.prettyPhoto.close()", 8000);

        });

changepicturecallback给了我一个“_bsap未定义”的错误(在firebug中看到)所以我对它进行了评论。

以下是我用于测试的剪贴页面: http://www.fortmitchellwalmart.com/prettyPhotoTest/index.html

我不知道如何使用cookie boolean禁用它,我几乎是javascripting和flash的noob,但希望这有帮助!

相关问题