2010-09-24 116 views
0

我對Jquery真的很陌生,我發現了幾個使用cookie和onload功能打開燈箱的例子。我正在使用與fancybox一起使用的cookie示例,但我一直在我的所有網站上使用prettyPhoto,並且確實不想更改爲fancybox。我嘗試了十幾種不同的方式來使這個工作,但我沒有運氣。這是我的代碼。任何幫助或建議都會很棒。如何在頁面加載時自動打開prettyPhoto lightbox?

$(文件)。就緒(函數(){

// !!! 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評論= 「」;

功能showLbox(){$ .prettyPhoto.open(其中,標題,評論);} // 在頁面加載顯示模式對話框 //有關您可以找到的選項的更多信息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 }); 


    }); 
} 

});

+0

請修復您的代碼標籤:) – Bjorn 2010-09-24 20:41:54

回答

2

頁面加載完成後,您將不得不調用S.prettyPhoto.open API函數。我把它下的$(文件)。就緒(函數()函數:

$(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沒有定義」的錯誤(看到螢火蟲),所以我評論它

下面是我用的測試廢頁: http://www.fortmitchellwalmart.com/prettyPhotoTest/index.html

我不知道如何使用cookie的布爾禁用它,我幾乎用JavaScript編程和Flash一個noob,但希望這有助於

相關問題