2012-05-23 59 views
0

我試圖通過檢測圖像是否在視圖中然後下載來克服移動設備上的圖像大小下載限制。還需要做相反的處理,並用較小的圖像替換圖像src以釋放內存。有誰知道如何在視圖中最好地檢測圖像,並在jQuery Mobile下進行對比?如何檢測圖像元素? (jQuery Mobile)

Ps。我正在嘗試使用unveil.js,但目前爲止還沒有運氣。

回答

0

我想你是指活動頁面內的圖像。在這種情況下,這將檢索包含的所有圖片:

$.mobile.activePage.find('img'); 

編輯:

$.mobile.activePage.find('img').each(function(index, el){ 
    var pos = $(el).position().top; 
    var current = $(window).scrollTop(); 
    var height = $(window).height(); 
    if((pos > current) && (pos < current + height)) { 
     // the image is in the viewport 
    } else { 
     // the image is not in the viewport 
    } 
}); 
+0

不,我的意思是在實際視圖圖像。 – tkane

+0

你是什麼意思?整個HTML? – davids

+0

視窗(頁面的可見部分) – tkane