图片预载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;
}
}


猜你喜欢
- 本文实例为大家分享了wxPython电子表格功能的具体代码,供大家参考,具体内容如下#!/usr/bin/env python#encodi
- 无法导入本地安装好的第三方库一、安装第三方库1、 Anaconda安装(1)、打开“cmd”窗口(快
- 1、首先介绍简单的try......except尝试运行的放例如下面的图和代码来简单介绍下:def test(x,y): pri
- 如下:re.split(pattern, string, [maxsplit], [flags])pattern:表示模式字符串,由要匹配的
- 一张表(ColumnTable)的结构如下图所示当前需要实现的功能:通过Number的值为67来获取当前的节点ID、父节点ID递归实现SQL
- 如下所示:b.reset_index(drop=True)reset_index代表重新设置索引,drop=True为删除原索引。来源:ht
- default-character-set=gbk #或gb2312,big5,utf8 然后重新启动mysql 运行->servic
- 一、问题实现对文本的分句,大致来说主要是以中文的句号、感叹、问号等符号进行分句。难点在于直接分句可能会造成人物说话的语句也被分开!二、步骤分
- Oracle数据库以其高可靠性、安全性、可兼容性,得到越来越多的企业的青睐。如何使Oracle数据库保持优良性能,这是许多数据库管理员关心的
- 本文以实例形式分析了Python多进程编程技术,有助于进一步Python程序设计技巧。分享给大家供大家参考。具体分析如下:一般来说,由于Py
- 因为权限不够,导致Pycharm在运行脚本时报错:socket.error: [Errno 1] Operation not permitt
- JS数组遍历普通函数优点:支持流程控制(break、continue、return)forconst arr = ["A"
- 一、出现原因:readline模块没有安装二、解决方式:# 安装readline模块yum -y install readline-deve
- 1. 引言最近在将一个算法由matlab转成python,初学python,很多地方还不熟悉,总体感觉就是上手容易,实际上很优雅地用pyth
- 有一个ssqdatav2数据,要找到其中的深圳,并且替换成圳。因为收集到的数据出现了错误,本来只有省份简写的地方却出现了深圳。如何找到DF中
- 一、爬取豆瓣热评该程序进行爬取豆瓣热评,将爬取的评论(json文件)保存到与该python文件同一级目录 * 意需要下载这几个库:reques
- 又有人说设session.timeout=99999。这种同样不行,session有最大时间限制。我经过测试发现最大值为24小时,也就是说你
- 关于“登录”和“注册”的问题已经被很多设计师和交互设计上写过无数遍了,今天我在登录纳米盘网站时受到打击了所以写下此文。事情是这样的:当初租用
- MaxDB和MySQL是独立的数据库管理服务器。系统间的协同性是可能的,通过相应的方式,系统能够彼此交换数据。要想在MaxDB和MySQL之
- --创建测试表 DECLARE @Users TABLE ( ID INT IDENTITY(1,1), UserInfo XML ) --