jquery实现图片自动播放

本文介绍了一个使用HTML和JavaScript实现的简单图片轮播效果。通过设置定时器自动切换图片,并利用鼠标悬停事件来改变显示的图片。同时,提供了停止自动播放的功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<!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>test</title>
<style>
ul{ margin:0px;padding:0px;width:360px;}
li{ float:left; margin-left:10px; list-style-type:none;width:40px;background-color:#96EDE4;text-align:center;}
img{ width:166px;height:112px;}
#stop{ clear:both;}
</style>
<script src="jquery.js"></script>
</head>

<body>
<div><img src="img/1.gif" id='img1' /></div>
<div><ul><li id='1'>1</li><li id='2'>2</li><li id='3'>3</li></ul></div>
<div id='stop'><input type="button" value="停止自动播放"</div>


<script>
function showImg1(){
 $('#img1').attr('src','img/1.gif');
}
function showImg2(){
 $('#img1').attr('src','img/2.gif');
}
function showImg3(){
 $('#img1').attr('src','img/3.gif');
}
function autoShow(){
 setT1 = setTimeout('showImg2()',1000);
 setT2 = setTimeout('showImg3()',2000);
 setT3 = setTimeout('showImg1()',3000);
}

function clearTimeSet(){
 clearTimeout(setT1);
 clearTimeout(setT2);
 clearTimeout(setT3);
}

var int = setInterval("autoShow()",3000);

$('#stop').click(function(){
 clearTimeSet();
 int = window.clearInterval(int); 
})

$('li').mouseover(function(){

 if($(this).attr('id') == '1'){
   
  int = window.clearInterval(int);
  clearTimeSet();
  showImg1(); 
   
 }else if($(this).attr('id') == '2'){
  
  int = window.clearInterval(int); 
  clearTimeSet();
  showImg2();
  
 }else if($(this).attr('id') == '3'){
  
  int = window.clearInterval(int);
  clearTimeSet();
  showImg3(); 
 }
})

$('li').mouseout(function(){
 int = setInterval("autoShow()",3000);
})

</script>
</body>
</html>
                                                                                                                            

                                                                                                                             李汉团   Mar 9,2012

转载于:https://my.oschina.net/adamboy/blog/43699

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值