前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >轮播图中点按钮停止后等几秒再自动播放的代码

轮播图中点按钮停止后等几秒再自动播放的代码

作者头像
用户1730674
发布2018-05-02 11:03:23
9590
发布2018-05-02 11:03:23
举报
文章被收录于专栏:我分享我快乐我分享我快乐

<!doctype html>

<html>

<head>

<script src="jquery.js"></script>

<style>

div{float:left;width:100px;overflow:hidden;}

span{position:relative;float:left;width:400px;}

div img{width:100px;height:100px;float:left;}

</style>

<meta charset="utf-8">

<title>无标题文档</title>

</head>

<body>

<div>

<span>

<img style="background-color:red;">

<img style="background-color:green;">

<img style="background-color:blue;">

<img style="background-color:red;">

<span>

</div>

<input type="button" value="1">

<input type="button" value="2">

<input type="button" value="3">

<script>

var n=0

function run(){

if(n<3){n++}else{

n=1;

$("span").css({left:0})

}

$("span").stop(true,true).animate({left:-100*n},500)

}

var t = setInterval(run,2000)

$("input").click(

function(){

clearInterval(t)//点按钮停止之前的定时器

n=$("input").index(this)

$("span").stop(true,true).animate({left:-100*n},500)

setTimeout(function(){//点按钮后4秒中后重新定时

clearInterval(t)//避免连续点击按钮重复定时

t = setInterval(run,2000)

},4000)//4秒

}

)

</script>

</body>

</html>

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2016-08-31,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 我分享我快乐 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档