Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何检测视图中的图像元素?(jquerymobile)_Javascript_Jquery_Jquery Mobile - Fatal编程技术网

Javascript 如何检测视图中的图像元素?(jquerymobile)

Javascript 如何检测视图中的图像元素?(jquerymobile),javascript,jquery,jquery-mobile,Javascript,Jquery,Jquery Mobile,我试图通过检测图像是否在视图中,然后下载来克服移动设备上的图像大小下载限制。还需要做相反的事情,用较小的映像替换映像src以释放内存。有人知道如何在jquerymobile下最好地检测视图中和对面的图像吗 顺便说一句,我正在努力工作,但到目前为止运气不佳。我想你指的是活动页面中的图像。在这种情况下,将检索其中包含的所有图像: $.mobile.activePage.find('img'); 编辑: $.mobile.activePage.find('img')。每个(函数(索引,el){ va

我试图通过检测图像是否在视图中,然后下载来克服移动设备上的图像大小下载限制。还需要做相反的事情,用较小的映像替换映像src以释放内存。有人知道如何在jquerymobile下最好地检测视图中和对面的图像吗


顺便说一句,我正在努力工作,但到目前为止运气不佳。

我想你指的是活动页面中的图像。在这种情况下,将检索其中包含的所有图像:

$.mobile.activePage.find('img');
编辑:

$.mobile.activePage.find('img')。每个(函数(索引,el){
var pos=$(el).position().top;
var current=$(窗口).scrollTop();
var height=$(window.height();
如果((位置>当前)和((位置<当前+高度)){
//图像位于视口中
}否则{
//图像不在视口中
}
});

不,我指的是实际视图中的图像。视图是什么意思?整个html?视口(页面的可见部分)谢谢!明天我将测试代码,因为现在是回家的时候了…:)
$.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
    }
});