JQuery实现图片的预加载与延时加载

转自:http://www.rjboy.cn/?p=1002

 

本人博客已经迁移至 www.shangyang.me 欢迎大家访问

 

预加载,

function loadimg(arr,funLoading,funOnLoad,funOnError){
	var numLoaded=0,
	numError=0,
	isObject=Object.prototype.toString.call(arr)==="[object Object]" ? true : false;
 
	var arr=isObject ? arr.get() : arr;
	for(a in arr){
		var src=isObject ? $(arr[a]).attr("data-src") : arr[a];
		preload(src,arr[a]);
	}
 
	function preload(src,obj){
		var img=new Image();
		img.onload=function(){
			numLoaded++;
			funLoading && funLoading(numLoaded,arr.length,src,obj);
			funOnLoad && numLoaded==arr.length && funOnLoad(numError);
		};
		img.onerror=function(){
			numLoaded++;
			numError++;
			funOnError && funOnError(numLoaded,arr.length,src,obj);
		}
		img.src=src;
	}
 
}

参数说明:
  arr:可以是存放图片路径的一个数组,也可以是选取到的img的jquery对象;
  funLoading:每一个单独的图片加载完成后执行的操作;
  funOnLoad:全部图片都加载完成后的操作;
  funOnError:单个图片加载出错时的操作。

 

懒加载,

var imgonload=function(errors){
        /*errors:加载出错的图片数量;*/
	console.log("loaded,"+errors+" images loaded error!");
}
 
var funloading=function(n,total,src,obj){
        /*
        n:已加载完成的数量;
        total:总共需加载的图片数量;
        src:当前加载完成的图片路径;
        obj:当loadimg函数中传入的arr为存放图片路径的数组时,obj=src,是图片路径,
               当arr为jquery对象时,obj是当前加载完成的img dom对象。
       */
	console.log(n+"of"+total+" pic loaded.",src);
	var newimg = document.createElement("img");
	newimg.src=src;
	$("body").append(newimg).fadeIn();
}
 
var funloading_obj=function(n,total,src,obj){
	console.log(n+"of"+total+" pic loaded.",src);
	$(obj).attr("src",src);
	$(obj).fadeIn(200);
}
 
var funOnError=function(n,total,src,obj){
	console.log("the "+n+"st img loaded Error!");
}

 

调试用例,

console.log("loading...");
loadimg($("img"),funloading_obj,imgonload,funOnError);
/*loadimg(["http://pic22.nipic.com/20120619/9607634_212642465144_2.jpg",
		 "http://pic21.nipic.com/20120531/1670912_103610084349_2.jpg",
		 "http://pic21.nipic.com/20120616/4952071_130629530136_2.jpg",
		 "http://pic21.nipic.com/20120610/1723580_105037029000_2.jpg",
		 "http://pic22.nipic.com/20120617/2572038_125013326121_2.jpg"
		],funloading,imgonload,funOnError);*/

 

 

 

M6 Mac mini涨价2500值不值?深度拆解硬件成本与购买决策 统一内存架构将CPU、GPU和内存封装在一起,通过共享高带宽内存池提升数据交换效率,尤其适合本地AI推理和视频渲染等场景。在苹果生态中,起步内存和存储的配置直接决定设备生命周期,因为后期无法自行升级。M6 Mac mini将起步内存从16GB提升至24GB、存储从256GB提升至512GB,同时芯片制程和GPU核心数均有升级,持续负载性能保持率明显改善。对于开发者、内容创作者和本地大模型推理用户,这些变化能转化为实际效率收益;而轻度办公用户则可能面临性能冗余。理解硬件成本结构与自身工作流需求,才能判断这25 阅读详情

相关推荐

无刷电机FOC控制入门:磁场、洛伦兹力与坐标转换详解

本文深入解析无刷电机FOC(磁场定向控制)的核心原理,从电磁学基础的磁场与洛伦兹力出发,详细阐述了如何通过Clarke变换、Park变换等坐标转换技术,将三相交流解耦为直流量进行控制,最终利用SVPWM技术实现平滑、高效的电机驱动。文章旨在帮助开发者理解FOC的物理本质与数学框架,为机器人、无人机等高性能应用奠定基础。

weixin_29306011的博客 267

jquery实现图片预加载

代码如下 <div class="box"> <p> <a href="javascript:;" class="btn" data-control="prev">上一页</a> <a href="javascript:;" class="btn" data-control="next">下一页...

qq_39025670的博客 741

KiCad 7.0 + 嘉立创打样:从原理图到实物,打造你的双LLCC68 LoRa串口透传板

本文详细介绍了使用KiCad 7.0设计双LLCC68 LoRa串口透传板的完整流程,从原理图设计到嘉立创打样。重点解析了AVR+LLCC68组合的优势、双模块布局的电磁兼容设计、SPI接口配置及射频走线技巧,并提供了实测数据和常见问题解决方案,帮助开发者高效实现物联网设备的低功耗远距离通信。

weixin_28693447的博客 260

[转]Javascript实现图片的预加载的完整实现

图片预加载是web开发中一种应用相当广泛的技术,比如我们在做图片翻转显示等特效的时候,为了让图片在转换的时候不出现等待,我们最好是先让图片下载到本地,然后在继续执行后续的操作。今天我们将来实现一个完整的图片预加载和处理图片加载后执行后续操作的代码。 下面的函数实现了一个我们想要的最基本的图片预加载效果 functionpreloadimages(arr){var...

weixin_30678821的博客 674

别再到处找包了!Keil5芯片支持包(Pack)最全管理指南:安装、更新、迁移与离线备份

本文详细解析了Keil5芯片支持包(Pack)的全生命周期管理,包括安装、更新、迁移与离线备份的工程化解决方案。针对STM32F10x等常见芯片,提供了高效获取Pack的策略、版本管理技巧及团队协作方案,帮助开发者解决常见的'Device Family Pack missing'等问题,提升嵌入式开发效率。

weixin_28729205的博客 540

Xilinx Vivado LDPC IP core,TSN IP core. 各种IP core

Xilinx Vivado LDPC IP core,TSN IP core. 各种IP core

qq_1432825237的博客 3991

页面加载完毕后执行事件

页面加载完成后触发事件很简单, 写这个的原因是因为,每次用到的时候总是忘了怎么写。。。 首先最简单的方法。jquery的一种简写形式: $(function(){ alert("页面加载完成!"); }); 其对应的完整形态为: $(document).ready(function(){ alert("页面加载完成!"); }); ...

banghe8611的博客 2150

XIAO ESP32S3 Sense摄像头与麦克风实战:从硬件连接到AI语音视觉项目

本文详细介绍了如何使用Seeed Studio XIAO ESP32S3 Sense开发板进行AI语音视觉项目开发。从硬件连接到Arduino环境搭建,再到摄像头拍照、视频流传输、麦克风录音等实战操作,最后引导读者探索基于TensorFlow Lite Micro的语音唤醒和SenseCraft AI的图像识别等AI应用,为物联网和边缘AI项目提供了完整的入门指南。

xray4的博客 1023

Jquery实现图片的预加载与延时加载

有很多项目经常会需要判断图片加载完成后执行相应的操作,或者需要图片延迟加载,网上虽然已经有很不错的插件,但要为这些效果还得单独加载一个插件的话总感觉有点不舒服,干脆自己写了个方法: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 ...

weixin_30872733的博客 102

5分钟搞定Nano-Banana图片编辑API对接:从Base64编码到生成图片全流程

本文详细介绍了如何快速对接Nano-Banana图片编辑API,基于gemini-2.5-flash-image-preview模型,从环境准备、Base64编码到API调用的全流程。通过实战示例和优化技巧,帮助开发者高效集成AI图片处理能力,提升产品竞争力。

dog123的博客 260

java三角套利_三角对冲套利-EA原理全解析

它是两个直盘货币和一个交叉盘货币之间的相互对冲,交易员往往受到外界因素的影响无法严格执行造成亏损。该系统经过大量数据统计分析和严格的科学论证计算,并通过多年实盘交易验证可以达到稳定盈利。希望交易员严格按照交易规则执行。此策略利用交叉外汇对的市场价格与其合成价格的价差来实现套利,还以EUR/USD和GBP为例:1,我们关注三个外汇对:EUR/USD,GBP/USD,以及GBP/EUR2,计算GBP/...

weixin_29531897的博客 2418

php如何使用ajax实现延时加载图片,延迟加载图片的 jQuery 插件Lazy Load(图片预加载实现方法)...

延迟加载图片的 jQuery 插件Lazy Load(图片预加载实现方法)为了提高用户的访问体验和访问速度,一些图片很多的网页大都使用了这种技术,就是图片的预加载,当光标滚动到相应的图片,图片才慢慢的显示出来,,Lazy Load插件主要就是实现了这个功能。Lazy Load 是一个用 JavaScript 编写的 jQuery 插件. 它可以延迟加载长页面中的图片. 在浏览器可视区域外的图片不会...

weixin_39995764的博客 206

税务某局 webpack 登录接口逆向分析

我们再回到接口逻辑去看一下,发现每次请求前,还有两个接口,getpublickey和sendsm4,这里分析了一下调用逻辑,sm4这个接口用到一个参数是由publickey返回的一个参数而来,这个参数又经过内部加密处理,我们找到这个参数加密的地方,大概是在这个位置。我们还是顺着逻辑将加载器扣下来,然后用一个变量去接收,有了加载器,我们直接把加密代码扣下来做下处理,把一些用到的参数整理下如下。打上断点分析后,_utils_getuuid这个很长的变量也是加载器的一个函数,我们将这段代码也扣下来,如下。

码王吴彦祖的博客 402

jQuery使用技巧

禁止右键点击:$(document).ready(function(){ $(document).bind("contextmenu",function(e){ return false; }); });预加载图片$(document).ready(function() { jQuery.preloadImages = function() { for(var i = 0; i<ARGUMENTS.

学而不思则罔 思而不学则殆 529

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

html加载首页图片加载慢,html首页 如何解决banner大图加载太慢的问题?

banner 无缝轮播,想要在页面加载的时候先加载第一张图,等轮播到第二张图片的时候第二张图片再加载出来 ,如何实现?首先声明,不知道你的服务器架构适不适合;我现在的移动端项目,也涉及了这个问题;我这边是这样实现的:1,轮播第一张改用base64加入首页html流,页面加载完毕后(第二屏懒加载;所以,加载完毕基本等于第一屏所有组件、图片加载完毕);2,延时触发轮播(延时是基于集群的相应时间自动调整...

weixin_28801391的博客 1990

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Javascript图片预加载和图片延时加载l两者的区别

JavaScript图片预加载和图片延时加载的区别主要体现在图片传输到客户端的时间上,都是为了提高用户体验的。   两者技术的本质:两者的行为是相反的,一个是提前加载,一个是延缓甚至不加载。预加载会增加服务器前端压力,延时加载对服务器前端有一定的缓解压力。   延时加载:主要目的是作为服务器前端优化,减少请求数或延迟请求数,一些图片非常多的网站中非常有用,在浏览器可视区域外的图片不会被载入,直

phycsdn的博客 393

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

非常好的javascript 代码

与其他Javascript类库冲突解决方案 $(document).ready(function() { var $jq = jQuery.noConflict(); $jq('#id').show(); }); 使元素居屏幕中间位置 $(document).ready(function() { jQuery.fn.center =...

weixin_30846599的博客 59

前端开发都会的35个Jquery小技巧

1. 禁止右键点击 $(document).ready(function(){ $(document).bind("contextmenu",function(e){ return false; }); }); 2.隐藏搜索文本框文字 Hide when clicked in the search field, the value.(example c

vvhh22的博客 861

每个程序员都会的35个jQuery技巧

1. 禁止右键点击 $(document).ready(function(){     $(document).bind("contextmenu",function(e){         return false;     }); });  2. 隐藏搜索文本框文字 Hide when clicked in the search field, the value.(example c

独自等待的专栏 314

一些有用的js方法

1. 禁止右键点击 $(document).ready(function(){     $(document).bind("contextmenu",function(e){         return false;     }); }); 2. 隐藏搜索文本框文字 Hide when clicked in the search field, the value.(exampl

lglbingpo的博客 352

Jquery使用小技巧

1.禁止右键使用 viewplaincopytoclipboardprint? 1.$(document).ready(function(){ 2.$(document).bind("contextmenu",function(e){ 3.returnfalse; 4....

weixin_30832983的博客 95

jQuery 使用小技巧

/*1.Disableright-click(禁用右键)Disableright-clickcontextualmenu.*/$(document).ready(function(){$(document).bind(”contextmenu”,function(e){returnfalse;});});/*...

weixin_30337251的博客 128
上一篇: Cruise Control 持续集成 - 如何自动编译,打包,并自动发布至Tomcat
下一篇: 部署Tomcat
伤神v
博客等级 码龄19年 17粉丝 129原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值