沉沙
2018-06-28
来源 :
阅读 1700
评论 0
摘要:本篇教程通过代码讲解了jQuery的自动播放选项卡,希望阅读本篇文章以后大家有所收获,帮助大家对jQuery的理解更加深入。
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
<script src="js/jquery-1.12.3.min.js"></script>
<style>
.box div {
width:200px;
height:200px;
border: 1px solid #000;
display: none;
}
.box input.active {
background: yellow;
}
.box div.on{
display: block;
}
</style>
</head>
<body>
<div>
<input type="button" value="按钮1">
<input type="button" value="按钮2">
<input type="button" value="按钮3">
<div>昨天是2017年的元旦</div>
<div>今天是2017年的第二天</div>
<div>加油加油</div>
</div>
<script>
$(function(){ $('input').click(function(){
$(this).addClass('active').siblings().removeClass('active');
$('.box>div').eq($(this).index()).addClass('on').siblings().removeClass('on');
});
// 自动播
function move(){
i++;
$('input').eq(i).addClass('active').siblings().removeClass('active');
$('.box>div').eq(i).addClass('on').siblings().removeClass('on');
if(i==2){
i=-1;
}
}
var timer = null;
var i = 0;
timer = setInterval(move,1000);
$('.box').mouseover(function(){
clearInterval(timer);
});
$('.box').mouseout(function(){
timer = setInterval(move,1000);
})
});
</script>
</body>
</html>
本文由职坐标整理并发布,了解更多内容,请关注职坐标WEB前端jQuery频道!
喜欢 | 0
不喜欢 | 2
您输入的评论内容中包含违禁敏感词
我知道了

请输入正确的手机号码
请输入正确的验证码
您今天的短信下发次数太多了,明天再试试吧!
我们会在第一时间安排职业规划师联系您!
您也可以联系我们的职业规划师咨询:
版权所有 职坐标-一站式AI+学习就业服务平台 沪ICP备13042190号-4
上海海同信息科技有限公司 Copyright ©2015 www.zhizuobiao.com,All Rights Reserved.
沪公网安备 31011502005948号