2010-05-22 66 views
0

我正在做一個網站,我需要根據分辨率動態更改一張幻燈片中的項目數量。我使用jQuery工具滾動jQuery Scrollable Dynamic

爲了更好地理解,這裏是基本標記

<div class="scrollable"> 

    <!-- root element for the items --> 
    <div class="items"> 

     <!-- 1-5 --> 
     <div> 
     <img src="http://farm1.static.flickr.com/143/321464099_a7cfcb95cf_t.jpg" /> 
     <img src="http://farm4.static.flickr.com/3089/2796719087_c3ee89a730_t.jpg" /> 
     <img src="http://farm1.static.flickr.com/79/244441862_08ec9b6b49_t.jpg" /> 
     <img src="http://farm1.static.flickr.com/28/66523124_b468cf4978_t.jpg" /> 
     <img src="http://farm1.static.flickr.com/164/399223606_b875ddf797_t.jpg" /> 
     </div> 

     <!-- 5-10 --> 
     <div> 
     <img src="http://farm1.static.flickr.com/163/399223609_db47d35b7c_t.jpg" /> 
     <img src="http://farm1.static.flickr.com/135/321464104_c010dbf34c_t.jpg" /> 
     <img src="http://farm1.static.flickr.com/40/117346184_9760f3aabc_t.jpg" /> 
     <img src="http://farm1.static.flickr.com/153/399232237_6928a527c1_t.jpg" /> 
     <img src="http://farm1.static.flickr.com/50/117346182_1fded507fa_t.jpg" /> 
     </div> 

     <!-- 10-15 --> 
     <div> 
     <img src="http://farm4.static.flickr.com/3629/3323896446_3b87a8bf75_t.jpg" /> 
     <img src="http://farm4.static.flickr.com/3023/3323897466_e61624f6de_t.jpg" /> 
     <img src="http://farm4.static.flickr.com/3650/3323058611_d35c894fab_t.jpg" /> 
     <img src="http://farm4.static.flickr.com/3635/3323893254_3183671257_t.jpg" /> 
     <img src="http://farm4.static.flickr.com/3624/3323893148_8318838fbd_t.jpg" /> 
     </div> 

    </div> 

</div> 

好了,現在我想設置,如果我有一個決議波紋管1440,我只會顯示例如3圖片

<div class="scrollable"> 
     <!-- root element for the items --> <div class="items"> 

     <!-- 1-3 --> 
     <div> 
     <img src="http://farm1.static.flickr.com/143/321464099_a7cfcb95cf_t.jpg" /> 
     <img src="http://farm4.static.flickr.com/3089/2796719087_c3ee89a730_t.jpg" /> 
     <img src="http://farm1.static.flickr.com/79/244441862_08ec9b6b49_t.jpg" /> 
     </div> 

     <!-- 3-6 --> 
     <div> 
     <img src="http://farm1.static.flickr.com/163/399223609_db47d35b7c_t.jpg" /> 
     <img src="http://farm1.static.flickr.com/135/321464104_c010dbf34c_t.jpg" /> 
     <img src="http://farm1.static.flickr.com/40/117346184_9760f3aabc_t.jpg" /> 
     </div> 

    ..etc 
      </div> 
    </div> 

我知道我應該使用screen.width();函數,但如何根據分辨率對其進行分割和解析?

感謝您的意見!

回答

0

如果這是你唯一的規則,那麼你將要設置:

​$(document).ready(function() { 
    if (screen.width < 1440){ 
     var i = $("img").clone(); 
     $('.items div').remove(); 
     for (var a = 0; a <= i.length/3; a++){ 
      var d = $('<div></div>'); 
      d.append(i.slice(a * 3 - 3, a * 3)); 
      $('.items').append(d); 
     } 
    } 
});​ 

我認爲這解決了船。提供玩具空間http://jsfiddle.net/NBf2u/

1

你可以在這裏使用JQuery的:gt選擇:

$(function(){ 
if (screen.width() < 1440) 
{ 
    $('div.scrollable img:gt(2)').hide(); // hide other images and show only three 
} 
// you can setup similar if conditions for other cases. 
});