js代码 scroll.photo.js :

window.imgscroll = {
options: {
target: null, //插入图片的目标位置
img_list: null, //图片数组 [{ url: "/CMF01_000.jpg"},{ url: "/CMF01_001.jpg"}]
img_max: 0, //图片数量
img_num: 0, //图片累计已加载的数量
step_max: 3, //每轮加载图片的数量 从0开始计数
step_num: 0, //每轮已加载图片的数量
img_obj: new Image(),
s_scroll: 0, //滑动条的Y轴位置
w_height: 0, //页面内容的高度
l_height: 500, //小于此参数则开始加载图片
w_width: 640 //浏览器窗口宽度
},
onLoad: function(){
if(this.options.img_num >= this.options.img_max){
$("#img_load").hide(); //隐藏loading图标
return;
}
this.options.img_obj.src = this.options.img_list[this.options.img_num].url;
this.options.img_obj.onload = function(){
imgscroll.endLoad(this.width);
};
},
endLoad: function(width){
width = this.options.w_width > width? width+"px": "98%";
this.options.target.append('<div style="text-align:center;color:#999;padding-bottom:10px;"><img src="'+this.options.img_list[this.options.img_num].url+'" width="'+width+'"><br /><span>'+ (this.options.img_num+1) +'/'+ this.options.img_max +'</span></div>');
     this.options.img_num += 1;
if(this.options.step_num < this.options.step_max){this.options.step_num += 1;
this.onLoad();
}else{
//结束一轮加载后将每轮已加载图片数量归零
this.options.step_num = 0;
}
},
beLoad: function(target,img_list){
this.options.target = target;
this.options.img_list = img_list;
this.options.img_max = img_list.length;
this.options.l_height = $(window).height()*2;
this.options.w_width = $("body").width();
//绑定滑动条的判定
$(window).scroll(function(){
imgscroll.options.s_scroll = $(window).scrollTop();
imgscroll.options.w_height = $("body").height();
if((imgscroll.options.w_height-imgscroll.options.s_scroll) < imgscroll.options.l_height){
if(imgscroll.options.step_num < 1) imgscroll.onLoad();
}
});
this.onLoad();
} };

页面代码 :

<!DOCTYPE html>
<html>
<head>
<title>向下滚动页面加载图片</title>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="js/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="js/scroll.photo.js"></script>
<script type="text/javascript">var imglist = [{ url: "CMF01_000.jpg"},{ url: "CMF01_001.jpg"},{ url: "CMF01_002.jpg"},{ url: "CMF01_003.jpg"},{ url: "CMF01_004.jpg"},{ url: "CMF01_005.jpg"},{ url: "CMF01_006.jpg"}]; $(function(){
imgscroll.beLoad($("#img_list"),imglist);
});
</script> </head>
<body style="background:#444;padding-top:20px;">
<div id="img_list"></div>
<div id="img_load" style="text-align:center;color:#AAA;"><img src="loading.gif" /><br /><span>少女读取中...</span></div>
</body>
</html>

向下滚动页面加载图片的js的更多相关文章

  1. android列表停止滚动,加载图片,较为通用的一种办法

    在Adapter的itemView里面,判断列表是否在滚动中,其实是比较麻烦的,可能耦合性会比较严重. 所以考虑了下,是否能在itemView里面,检测列表的滚动状态,并监听停止状态加载图片,实现it ...

  2. jq常用事件(on,blur,focus,change),js/jq等待图片(页面)加载完毕事件,js读取文件

    jq常用事件(on,blur,focus,change) // 方法一(推荐) $('.box').on( "click",function() {} ) $('.box').on ...

  3. selenium chrome.options禁止加载图片和js

    #新建一个选项卡 from selenium import webdriver options = webdriver.ChromeOptions() #禁止加载图片 prefs = { 'profi ...

  4. jQuery实现的瀑布流效果, 向下滚动即时加载内容

    下拉滚动条或鼠标滚轮滚动到页面底部时, 动态即时加载新内容. 后台用 json 传输数据, 示例程序中只写了示例数组.数据也只设置了两个属性, 需根据实际应用改写.   页面用了 ul li 做为容器 ...

  5. android 解决启动页面加载图片空白以及去掉标题栏

    有时候启动页面根据白天晚上来启动时实现加载不同的图片效果,但是加载时会出现短暂的空白,解决方法如下: android:theme="@android:style/Theme.Transluc ...

  6. Android 滚动RecyclerView加载图片时的流畅度优化

    实现:使用onScrollStateChanged回调检测滚动状态,并在RecyclerViewAdapter内部设置类似isScrolling的状态值来控制网络图片的加载. 下面是代码举例: // ...

  7. 火狐浏览器怎么查看页面加载了那些js文件,那系js文件有作用

    方法一: 右击查看原代码,点击js链接如果能够看到文件内容,证明加载成功 方法二: 按F12键,如果控制台没有加载错误,证明加载成功:

  8. 【vue】css解决“防抖动”——防止页面加载图片抖动

    overflow:hidden;height:0;padding-bottom:*; // 其中*处填 图片的高宽百分比=高/宽*100%

  9. 页面加载时调用js函数方法

    方法一:在html的body中加入onload=""事件 <body onload='queryServer()'> </body> 方法二:jquery ...

随机推荐

  1. C语言 str2bin 和 bin2str 实现

    需求介绍 在编码或者调试过程中经常需要进行 字节码转换为 十六进制的字符串, 或者将 十六进制字符串 转换为 字节码的需求. 即:  字节码 (内存中存储的 01 串):    11111111 &l ...

  2. 【001:转载 eclipse中颜色的设置】

    转自于:http://www.cnblogs.com/arci/archive/2011/01/23/1942646.html Eclipse颜色设置 参考配色方案: http://www.cs.cm ...

  3. wcf服务与web发布时无法访问 几种解决办法

    1   如果wcf服务与web发布在同一iis目录下,没有跨域的问题   但发布前要修改 ServiceReferences.ClientConfig 把wcf服务地址改为你发布后的iis的ip地址( ...

  4. sublime设置备份

    Settings-user { "font_face": "Consolas", "font_size": 13, "line_p ...

  5. iOS 开发笔记-AFNetWorking https SSL认证

    一般来讲如果app用了web service , 我们需要防止数据嗅探来保证数据安全.通常的做法是用ssl来连接以防止数据抓包和嗅探 其实这么做的话还是不够的 . 我们还需要防止中间人攻击(不明白的自 ...

  6. Lucene学习总结

    在使用Lucene前,我们先大致熟悉下Lucene的几个核心类. 核心索引类: public class IndexWriter 索引过程的中心组件,把它想象成一个可以对索引进行写操作的对象. pub ...

  7. php程序员的水平 看看自己属于那个级别的

    文章链接:http://www.oschina.net/question/570781_60150?sort=time&p=4#answers

  8. Tsung安装与使用

    Tsung安装与使用 Tsung安装与使用的详细说明,包括测试场景的脚本配置说明 Ray 2013/11/11   目录 安装tsung Tsung运行环境安装... Tsung安装... 使用Tsu ...

  9. Android study first ----------安卓项目目录结构及adb指令

    #Android项目的目录结构 * Activity:应用被打开时显示的界面 * src:项目代码 * R.java:项目中所有资源文件的资源id * Android.jar:Android的jar包 ...

  10. Exchange Server 2013就地存档

    9.1就地存档 就地存档有助于重新获得对组织邮件数据的控制,而无需个人存储 (.pst) 文件,并且允许用户在可通过 Microsoft Outlook 2010及更高版本和 Microsoft Of ...