图片预载ImageLoader 1.1 Release
作者:dknt 发布时间:2008-11-04 20:04:00
特点:
1.图片预载入,载入后再显示。意图一次呈现,不会让一块一块下载破坏你的页面,绝佳的用户体验,颠覆传统的浏览器呈现图片的处理方式(需要后续函数支持)。
2.不会因载入图片造成脚本暂停假死,完全另一线程进行。不影响主程序流程。
3.提供及时的反馈,包括两方面的内容:1.正在载入什么图片 2.当前的百分数进度。大大提高留住用户眼球的概率,不会让用户因为苦等而离开。
4.容错支持,即使某个图片没有成功下载,也可以设置超时时间以便处理下一个图片。
5.多变的参数类型,尽最大可能方便使用。
相关文章:好用的JS图片预加载类
// save this as "image_loader.js"
//-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-//
/*
ImageLoader, Version 1.1, JavaScript
(c) 2006 Christian An <anchangsi@gmail.com>
With copyright not modified, you can use this program freely.
*/
//-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-//
function ImageLoader(className,Options){
this._ImageLoadStack = null;
this._currrentLoading = "";
this._FinalRun = false;
this.numLoaded = 0;
this.ClassName = className;
if(typeof(Options)=="undefined") Options = {};
if(isNaN(Options.Timeout) || Options.Timeout < 0 || Options.Timeout >100000){
this.EnableTimeout = false;
}else {
this.EnableTimeout = true;
this.Timeout = Options.Timeout;
}
if(typeof(Options.func)=="undefined"){
this.AfterFunction = null;
}else{
this.AfterFunction = Options.func;
}
if(typeof(Options.display)=="undefined"){
this.disDiv = null;
}else if(typeof(Options.display)=="string"){
this.disDiv = document.getElementById(Options.display);
}else if(typeof(Options.display)=="object"){
this.disDiv = Options.display;
}else{
this.disDiv = null;
}
if(typeof(Options.process)=="undefined"){
this.procDiv = null;
}else if(typeof(Options.process)=="string"){
this.procDiv = document.getElementById(Options.process);
}else if(typeof(Options.process)=="object"){
this.procDiv = Options.process;
}else{
this.procDiv = null;
}
if(typeof(document.imageArray)=="undefined") document.imageArray = new Array();
this.Load = function(){
var args = this.Load.arguments;
if(args.length!=0){
this._ImageLoadStack = new Array();
for(i=0; i<args.length; i++){
if(args[i].indexOf("#")!=0){
this._ImageLoadStack.push(args[i]);
}
}
}else if(this._ImageLoadStack == null){
this._runFinal();
}
this.numTotal = this._ImageLoadStack.length;
this._LoadAImage();
}
this._LoadAImage = function(){
if(this._ImageLoadStack.length!=0){
var sURL = this._ImageLoadStack.shift();
if(this.disDiv!=null) this.disDiv.innerHTML = sURL;
_currrentLoading = sURL;
var j = document.imageArray.length;
document.imageArray[j] = document.createElement("IMG");
document.imageArray[j].Owner = this;
document.imageArray[j].onload = function(){
this.Owner._LoadAImage();
this.onload = null;
}
document.imageArray[j].onerror = function(){
this.Owner._LoadAImage();
this.onload = null;
}
if(this.EnableTimeout){
window.setTimeout("if(_currrentLoading==\""+sURL+"\"){"+this.ClassName+"._LoadAImage()}",this.Timeout);
}
document.imageArray[j++].src = sURL;
if(this.procDiv!=null){
this.numLoaded++;
var percentage = Math.floor(this.numLoaded * 100 / this.numTotal);
this.procDiv.innerHTML = percentage;
}
}else{
this._runFinal();
}
}
this._runFinal = function(){
if(this._FinalRun == false){
this._FinalRun = true;
if(typeof(this.AfterFunction)=="function"){
this.AfterFunction();
}else if(typeof(this.AfterFunction)=="string"){
if (window.execScript){
window.execScript(this.AfterFunction);
}else{
window.eval(this.AfterFunction);
}
}
}
}
this.setLoadImages = function(imageArray){
if(typeof(imageArray)!="object") return;
this._ImageLoadStack = imageArray;
}
}
猜你喜欢
- 远程连接access数据库的几个方法: 1.建立VPN(Virtual Private Network),这样你的电脑和主机的连接
- 以下是SQL连接代码: 代码如下:Function Open_conn() dim Conn,Strconn&
- 函数可以参考:<% '注册论坛用户,参数说明 'username 用户登录名称 
- 数组我们已经提到过,对象是无序数据的集合,而数组则是有序数据的集合,数组中的数据(元素)通过索引(从0开始)来访问,数组中的数据可以是任何的
- 因为要用到过滤一组中重复的数据,使之变成没有重复的一组数据的功能,百度了一下,居然有朋友乱写,而且比较多,都没有认真测试过,只对字符可以,但
- 自从jQuery搞出特性侦探这东东,西方从来没有如此狂热研究浏览器。在以前javascript与DOM遍地是bug,美工主宰前端的年代,人们
- 首先说明,伪造访问来路不是什么光明正大的事情,目的就是为了欺骗服务器。原本以为给 XMLHTTP 对象增加一个 Referer 的heade
- 阅读之前:在看文章具体内容之前,希望你可以 先打开IE8,打开http://www.taobao.com,然后在地址栏里输入:javascr
- 一.概念简介 脚本:script是使用一种特定的描述性语言,依据一定的格式编写的可执行文件,又称作宏或批处理文件。 二.背景 近来在Wind
- 首先你要明白24bit的bmp图片的基本信息:1像素占3个字节,头部占54个字节。好了,现在开始做验证码了,这里以4位验证码(大小为20(高
- 引言委托 和 事件在 .Net Framework中的应用非常广泛,然而,较好地理解委托和事件对很多接触C#时间不长的人来说并不容易。它们就
- 我想做一个页面,10秒后转向其它页。想在网页中显示10秒的倒计时。谢谢了。对JS不懂 方法一:<html><h
- 每个进行过较大型的ASP-Web应用程序设计的开发人员大概都有如下的经历:ASP代码与页面HTML混淆难分,业务逻辑与显示方式绞合,使得代码
- 这是一个给新手学习代码的帖子,包含以下内容:如何使用UBB代码,如何用js与剪贴板交互,如何使用textRange对象,如何使用自定义的快捷
- 本教程将分步讲解如何使用JQuery和CSS打造一个炫酷动感菜单。jQuery的"write less, do more"
- 1 引言 在关系数据库(DB2,Oracle,Sybase,Informix和SQL Server)最小的恢复和交易单位为一个事务(Tran
- 最近我因为要安装 Firebug 1.4 导致我不得不安装了 Firefox 3.5 ,所以很不小心地接触到了Wordpress后台那漂亮的
- 作用: 构建一些简单的SQL语句,结合在提交表单时使用,可以较方便<%@LANGUAGE="VBSCRIPT&
- 在分析sIFR之前,先来快速的了解一下sIFR是什么,以及它是如何工作的。sIFR表示scalable Inman Flash Replac
- 1005:创建表失败1006:创建数据库失败1007:数据库已存在,创建数据库失败1008:数据库不存在,删除数据库失败1009:不能删除数