基于Jquery的简单图片切换效果
代码如下:
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script> <script type="text/javascript"> var t; var speed = 2;//图片切换速度 var nowlan=0;//图片开始时间 function changepic() { var imglen = $("div[name='pic']").find("div").length; $("div[name='pic']").find("div").hide(); $("div[name='pic']").find("div").eq(nowlan).show(); nowlan = nowlan+1 ==imglen ?0:nowlan + 1; t = setTimeout("changepic()", speed * 1000); } onload = function () { changepic(); } $(document).ready(function () { //鼠标在图片上悬停让切换暂停 $("div[name='pic']").hover(function () { clearInterval(t); }); //鼠标离开图片切换继续 $("div[name='pic']").mouseleave(function () { changepic(); }); }); </script> </head> <body> <div name="pic" style="float:left; position:relative;overflow:hidden;width:300px;height:240px;" > <div><img width="300" height="240" src="Chrysanthemum.jpg" alt="1"/></div> <div><img width="300" height="240" src="Desert.jpg" alt="2"/></div> <div><img width="300" height="240" src="Hydrangeas.jpg" alt="3"/></div> </div> </body> </html>
相关推荐
cas的无名 2020-02-18
chouliqingke 2020-02-13
云端轻躺 2007-09-04
GonaShrimp 2019-09-02
lionelf 2012-04-07
XTUxiaoxin 2011-09-01
shouen 2011-01-26
流萤 2019-06-26
dalong 2013-07-22
阳光之吻 2019-06-21
zgxzowen 2008-08-21
gcong 2019-06-13
liubang000 2015-08-17
sunshunli 2011-03-11
yangxinhua 2018-12-31
学无涯愈进而愈惘 2018-08-30
yinghuihong 2018-02-25