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

发布于 2024-09-24 19:53:18 字数 1456 浏览 3 评论 0原文

我对 Jquery 很陌生,我发现了几个使用 cookie 和 onload 功能打开灯箱的示例。我正在使用与 fancybox 一起使用的 cookie 示例,但我一直在我的所有网站上使用 PrettyPhoto,并且真的不想更改为 fancybox。我尝试了十几种不同的方法来让它发挥作用,但我没有运气。这是我的代码。任何帮助或建议都会很棒。

$(document).ready(function(){

// !!! 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 标题 = ""; var 注释 = "";

函数showLbox(){ $.prettyPhoto.open(其中,标题,评论); } // 在页面加载时显示模式框 // 有关选项的更多信息,您可以在 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 });


    });
}

});

I am really new to Jquery and I have found several examples of opening a light box using cookies and the the onload feature. I am using the cookie example which works with fancybox, but I have been using prettyPhoto on all my sites and really do not want to change to fancybox. I have tried a dozen different ways to get this to work but I have no luck. Here is my code. Any help or suggestions would be great.

$(document).ready(function(){

// !!! 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);
}
// on page load show the modal box
// more info about the options you can find on the fancybox site

    // 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 });


    });
}

});

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

白衬杉格子梦 2024-10-01 19:53:18

页面加载完成后,您必须调用 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 &height=399', '', 'Click anywhere to skip intro...');
            setTimeout("$.prettyPhoto.close()", 8000);

        });

changepicturecallback 给了我一个“_bsap 未定义”错误(在 firebug 中看到),所以我将其注释掉。

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

我不知道如何使用 cookie 布尔值禁用它,我对 javascript 和 flash 非常菜鸟,但希望这会有所帮助!

You will have to call the S.prettyPhoto.open API function after the page is done loading. I put it under the $(document).ready(function() 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 &height=399', '', 'Click anywhere to skip intro...');
            setTimeout("$.prettyPhoto.close()", 8000);

        });

changepicturecallback was giving me a "_bsap is not defined" error (seen in firebug) so i commented it out.

Here's the scrap page I was using for testing:
http://www.fortmitchellwalmart.com/prettyPhotoTest/index.html

I don't know how to disable it with the cookie boolean, I'm pretty much a noob with javascripting and flash, but hope this helps!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文