CeiWCJ 2011-01-06
代码如下:
<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>