页面加载后如何自动打开prettyPhoto灯箱? [英] How to open a prettyPhoto lightbox automatically when the page loads?
问题描述
我对Jquery真的很陌生,我发现了几个使用cookie和onload功能打开灯箱的示例.我正在使用可与fancybox一起使用的cookie示例,但我一直在所有站点上使用prettyPhoto,并且确实不想更改为fancybox.我尝试了十多种方法来使其正常工作,但是我没有运气.这是我的代码.任何帮助或建议都很好.
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(){
$(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其中="http://images.motortrend.com/photo_gallery/112_0611_39z+2006_bugatti_veyron+interior.jpg"; var title ="; var comment =";
var where = "http://images.motortrend.com/photo_gallery/112_0611_39z+2006_bugatti_veyron+interior.jpg"; var title = ""; var comment = "";
函数showLbox(){ $ .prettyPhoto.open(其中,标题,评论); } //在页面加载中显示模式框 //有关您可以在fancybox网站上找到的选项的更多信息
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 });
});
}
});
推荐答案
页面加载完成后,您将必须调用S.prettyPhoto.open API函数.我把它放在$(document).ready(function()函数下:
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给我一个未定义_bsap"的错误(在Firebug中看到),所以我将其注释掉了.
changepicturecallback was giving me a "_bsap is not defined" error (seen in firebug) so i commented it out.
这是我用来测试的剪贴簿页面: http://www.fortmitchellwalmart.com/prettyPhotoTest/index.html
Here's the scrap page I was using for testing: http://www.fortmitchellwalmart.com/prettyPhotoTest/index.html
我不知道如何使用cookie布尔值来禁用它,我对JavaScript和Flash几乎是个菜鸟,但是希望这对您有所帮助!
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!
这篇关于页面加载后如何自动打开prettyPhoto灯箱?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!