本文实例讲述了jQuery实现多屏图像图层切换效果的方法。分享给大家供大家参考。具体实现方法如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> <script type="text/javascript" src="jquery-1.6.2.min.js"></script> <style type="text/css"> ul{list-style:none;margin:0;padding:0;} li{float:left;} .Xing_focus{ width:875px; height:800px; overflow:hidden;border:1px solid red; } .Xing_focus ul{ width:3500px; } .bnt { float:left;width:300px;height:20px; border:1px solid red; } .bnt li{ width:18px;height:18px; background:red; cursor:pointer; margin-right:10px;float:left; } .bnt .sli{ background:blue; } .next{ width:100px;height:100px; background:#990000;float:left; cursor:pointer; } .pre{ width:100px;height:100px; background:#009;float:left; cursor:pointer;margin-right:30px; } .list1{ width:875px;height:500px;background:red; } .list2{ width:875px;height:500px;background:black; } .list3{ width:875px;height:500px;background:pink; } .list4{ width:875px;height:500px;background:blue; } </style> </head> <body> <div class="Xing_focus" id="box"> <ul class="imgs" id="actor"> <li class="list1"> <img src="/static/imghwm/default1.png" data-src="http://www.baidu.com/img/baidu_sylogo1.gif" class="lazy" / alt="jQuery实现的多屏图像图层切换效果实例_jquery" > </li> <li class="list2"> <img src="/static/imghwm/default1.png" data-src="http://www.baidu.com/img/baidu_sylogo1.gif" class="lazy" / alt="jQuery实现的多屏图像图层切换效果实例_jquery" > </li> <li class="list3"> <img src="/static/imghwm/default1.png" data-src="http://www.baidu.com/img/baidu_sylogo1.gif" class="lazy" / alt="jQuery实现的多屏图像图层切换效果实例_jquery" > </li> <li class="list4"> <img src="/static/imghwm/default1.png" data-src="http://www.baidu.com/img/baidu_sylogo1.gif" class="lazy" / alt="jQuery实现的多屏图像图层切换效果实例_jquery" > </li> </ul> <ul class="bnt" id="bnt"> </ul> <div class="pre" id="pre">上一张</div> <div class="next" id="next">下一张</div> </div> <script type="text/javascript"> $(window).load(function() { var liW = $("#actor li:first").width(); var liL = $("#actor li").length; //alert(liW) var lis = $("#actor li").length; for(i=0;i<lis;i++){ $("#bnt").append("<li></li>") $("#bnt li:first").addClass("sli"); }; $("#bnt li").each(function(index) { $(this).click(function(){ if($("#actor").is(":animated")==false){ $("#actor").animate({"marginLeft":-index*liW},500,function(){ $("#bnt li").removeClass("sli"); $("#bnt li").eq(index).addClass("sli"); }); }; }); }); settime=window.setInterval(atuoScroll,2000); $("#box").hover(function(){ window.clearInterval(settime); },function(){ settime=window.setInterval(atuoScroll,2000); }); //////////////////////////////////////// $("#next").click(function(){ var ulM =parseInt( $("#actor").css("margin-left")); if(ulM==-((liL-1)*liW)&&$("#actor").is(":animated")==false){ $("#actor").animate({"marginLeft":0+"px"},500,function(){ $("#bnt li").removeClass("sli"); $("#bnt li:first").addClass("sli"); }); } else if($("#actor").is(":animated")==false){ $("#actor").animate({"marginLeft":ulM-liW+"px"},500,function(){ var ulM =parseInt( $("#actor").css("margin-left")); var num = -ulM/liW $("#bnt li").removeClass("sli"); $("#bnt li").eq(num).addClass("sli"); }); }; }); //////////////////////////////////////// $("#pre").click(function(){ var ulM =parseInt( $("#actor").css("margin-left")); if(ulM==0&&$("#actor").is(":animated")==false){ $("#actor").animate({"marginLeft":-2625+"px"},500,function(){ $("#bnt li").removeClass("sli"); $("#bnt li:last").addClass("sli"); }); } else if($("#actor").is(":animated")==false){ $("#actor").animate({"marginLeft":ulM+liW+"px"},500,function(){ var ulM =parseInt( $("#actor").css("margin-left")); var num = -ulM/liW $("#bnt li").removeClass("sli"); $("#bnt li").eq(num).addClass("sli"); }); }; }); ////////////////////////////////////// });//END function atuoScroll(){ var liW = $("#actor li:first").width(); var liL = $("#actor li").length; var ulM =parseInt( $("#actor").css("margin-left")); if(ulM==-((liL-1)*liW)&&$("#actor").is(":animated")==false){ $("#actor").stop(); $("#actor").animate({"marginLeft":0},500,function(){ $("#bnt li").removeClass("sli"); $("#bnt li:first").addClass("sli"); }); } else if($("#actor").is(":animated")==false){ $("#actor").stop(); $("#actor").animate({"marginLeft":ulM-liW},500,function(){ var ulM =parseInt( $("#actor").css("margin-left")); var num = -ulM/liW $("#bnt li").removeClass("sli"); $("#bnt li").eq(num).addClass("sli"); }); }; }; </script> </body> </html>
希望本文所述对大家的jQuery程序设计有所帮助。

实现方法:1、用“$("img").delay(毫秒数).fadeOut()”语句,delay()设置延迟秒数;2、用“setTimeout(function(){ $("img").hide(); },毫秒值);”语句,通过定时器来延迟。

修改方法:1、用css()设置新样式,语法“$(元素).css("min-height","新值")”;2、用attr(),通过设置style属性来添加新样式,语法“$(元素).attr("style","min-height:新值")”。

区别:1、axios是一个异步请求框架,用于封装底层的XMLHttpRequest,而jquery是一个JavaScript库,只是顺便封装了dom操作;2、axios是基于承诺对象的,可以用承诺对象中的方法,而jquery不基于承诺对象。

增加元素的方法:1、用append(),语法“$("body").append(新元素)”,可向body内部的末尾处增加元素;2、用prepend(),语法“$("body").prepend(新元素)”,可向body内部的开始处增加元素。

在jquery中,apply()方法用于改变this指向,使用另一个对象替换当前对象,是应用某一对象的一个方法,语法为“apply(thisobj,[argarray])”;参数argarray表示的是以数组的形式进行传递。

删除方法:1、用empty(),语法“$("div").empty();”,可删除所有子节点和内容;2、用children()和remove(),语法“$("div").children().remove();”,只删除子元素,不删除内容。

on()方法有4个参数:1、第一个参数不可省略,规定要从被选元素添加的一个或多个事件或命名空间;2、第二个参数可省略,规定元素的事件处理程序;3、第三个参数可省略,规定传递到函数的额外数据;4、第四个参数可省略,规定当事件发生时运行的函数。

去掉方法:1、用“$(selector).removeAttr("readonly")”语句删除readonly属性;2、用“$(selector).attr("readonly",false)”将readonly属性的值设置为false。


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

ZendStudio 13.5.1 Mac
功能强大的PHP集成开发环境

EditPlus 中文破解版
体积小,语法高亮,不支持代码提示功能

螳螂BT
Mantis是一个易于部署的基于Web的缺陷跟踪工具,用于帮助产品缺陷跟踪。它需要PHP、MySQL和一个Web服务器。请查看我们的演示和托管服务。

SublimeText3 Linux新版
SublimeText3 Linux最新版

mPDF
mPDF是一个PHP库,可以从UTF-8编码的HTML生成PDF文件。原作者Ian Back编写mPDF以从他的网站上“即时”输出PDF文件,并处理不同的语言。与原始脚本如HTML2FPDF相比,它的速度较慢,并且在使用Unicode字体时生成的文件较大,但支持CSS样式等,并进行了大量增强。支持几乎所有语言,包括RTL(阿拉伯语和希伯来语)和CJK(中日韩)。支持嵌套的块级元素(如P、DIV),