2014-09-22 25 views
0

我使用jQuery 2.1.1,並用它來增加使用這種從數據庫「點擊」的行返回了:jQuery的IAS破可點擊排

<script type="text/javascript"> 
jQuery(function($) { 
    $('tbody tr[data-href]').addClass('clickable').click(function() { 
    window.location = $(this).attr('data-href'); 
    }); 
}); 
</script> 

這一直工作正常。我現在添加了jquery-ias(2.1.2),並且只有返回結果的第一頁有可點擊的行。

我的jQuery的IAS代碼如下:

<script type="text/javascript"> 
    $(document).ready(function() { 
      // Infinite Ajax Scroll configuration 
     jQuery.ias({ 
      container : '.wrap', // main container where data goes to append 
      item: '.item', // single items 
      pagination: '.nav', // page navigation 
      next: '.nav a', // next page selector 
      negativeMargin: 250, 
     }); 
    }); 
</script> 

jQuery的IAS工作正常,因爲所需的頁面加載,但是得到的行不能點擊。

在Chrome中檢查頁面顯示隨後加載的行沒有添加可點擊的屬性。

相關行中的PHP是這樣的:如果我請使用

<tr class='resultsrow item' <?php echo "data-href='carddetail.php?setabbrv={$row['setcode']}&number={$row['number']}&id={$row[1]}'"; ?>> 

一切工作正常,但如何讓他們很好地一起玩?

編輯.....

OK,我都圍繞它使用內置的pageChange事件的jQuery的IAS工作。

jQuery.ias().on('pageChange', function(pageNum, scrollOffset, url) { 
    var delay=1000; 
    setTimeout(function(){ 
    jQuery(function($) { 
     $('tbody tr[data-href]').addClass('clickable').click(function() { 
     window.location = $(this).attr('data-href'); 
     }); 
    }); 
    },delay); 
}); 

這樣當ias發現頁面發生變化時,它會等待頁面結構加載一秒鐘,然後應用可點擊的類。

如果它正在等待圖像,但我不能看到這個工作,雖然...不必爲這個實例,但有一個更好的方法來做到這一點。

任何指針?

回答

0

的更好的方式是使用rendered事件,例如:

jQuery.ias().on('rendered', function(item) { 
    var $items = jQuery(items); 

    $items.each(function() { 
    jQuery('tr[data-href]', $this).addClass('clickable').click(function() { 
     window.location = $(this).attr('data-href'); 
    }); 
    }); 
});