2011-07-08 108 views
2

我們同時使用兩個腳本:prettyPhotojQuery pagination。第一次加載頁面時,兩個腳本都在工作。但是,當我點擊分頁的第2頁時,燈箱不再顯示,但我仍然可以從一頁到另一頁。這些都爲雙方的初始化腳本:燈箱在jQuery分頁被觸發後不再有效(jQuery和lightbox衝突)

jQuery的分頁:

<script type="text/javascript"> 

      // This is a very simple demo that shows how a range of elements can 
      // be paginated. 
      // The elements that will be displayed are in a hidden DIV and are 
      // cloned for display. The elements are static, there are no Ajax 
      // calls involved. 

      /** 
      * Callback function that displays the content. 
      * 
      * Gets called every time the user clicks on a pagination link. 
      * 
      * @param {int} page_index New Page index 
      * @param {jQuery} jq the container with the pagination links as a jQuery object 
      */ 
      function pageselectCallback(page_index, jq){ 
       var new_content = jQuery('#hiddenresult div.result:eq('+page_index+')').clone(); 
       $('#Searchresult').empty().append(new_content); 
       return false; 
      } 

      /** 
      * Initialisation function for pagination 
      */ 
      function initPagination() { 
       // count entries inside the hidden content 
       var num_entries = jQuery('#hiddenresult div.result').length; 
       // Create content inside pagination element 
       $("#Pagination").pagination(num_entries, { 
        callback: pageselectCallback, 
        items_per_page:1 // Show only one item per page 
       }); 
      } 

      // When document is ready, initialize pagination 
      $(document).ready(function(){     
       initPagination(); 
      }); 
</script> 

prettyPhoto:

<script type="text/javascript" charset="utf-8"> 
    $(document).ready(function(){ 
    $("a[rel^='prettyPhoto']").prettyPhoto(); 
    }); 
</script> 

任何人都知道在哪裏的衝突是?謝謝。

回答

2

,我發現我的問題的解決方案(我在另一個論壇找到):

我只需要插入$(「一[相對^ =」prettyPhoto 「]「)prettyPhoto();功能pageselectCallback像這樣裏面:

function pageselectCallback(page_index, jq){ 
       var new_content = jQuery('#hiddenresult div.result:eq('+page_index+')').clone(); 
       $('#Searchresult').empty().append(new_content); 
       $("a[rel^='prettyPhoto']").prettyPhoto(); 
       return false; 
      } 

如果我只能給+1到誰回答了here的傢伙。 :)

1

嘗試使用jQuery .delegate()

$("a").delegate("[rel^='prettyPhoto']", "load", function() 
    { 

     $("a[rel^='prettyPhoto']").prettyPhoto(); 

    }); 
+0

仍然不顯示。我試着把它放在之間。 – catandmouse