level 1
几个div每隔十秒来回切换 怎样把鼠标放上时停止切换 鼠标离开自动切换
2018年06月19日 00点06分
1
level 1
可当我的鼠标放上的时候 它一直不停的闪是什么原因啊??
2018年06月19日 00点06分
3
没有清除定时器吧,我刚刚的bug就是这样
2018年06月19日 02点06分
level 1
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script type="text/javascript" src="js/jquery.min.js" ></script>
<script>
var i = 1;
$(document).ready(function(){
$("div").eq(0).show();
$("div").eq(1).hide();
$("div").eq(2).hide();
$("div").eq(3).hide();
var setin=window.setInterval(divtoggle,1000);
$("div").hover(function(){
window.clearInterval(setin);
},function(){
window.setInterval(divtoggle,1000);
})
})
function divtoggle(){
console.log(i);
if(i==4){i=0;}
console.log("a"+i+"a");
if(i==0){
$("div").eq(0).show();
$("div").eq(1).hide();
$("div").eq(2).hide();
$("div").eq(3).hide();
}
if(i==1){
$("div").eq(0).hide();
$("div").eq(1).show();
$("div").eq(2).hide();
$("div").eq(3).hide();
}
if(i==2){
$("div").eq(0).hide();
$("div").eq(1).hide();
$("div").eq(2).show();
$("div").eq(3).hide();
}
if(i==3){
$("div").eq(0).hide();
$("div").eq(1).hide();
$("div").eq(2).hide();
$("div").eq(3).show();
}
i++;
}
</script>
<style>
div{
width: 200px;
height: 200px;
}
</style>
</head>
<body>
<div style="background-color: aquamarine;"></div>
<div style="background-color: red;"></div>
<div style="background-color: deepskyblue;"></div>
<div style="background-color: gray;"></div>
</body>
</html>
2018年06月19日 02点06分
10
刚刚发现有个bug...
2018年06月19日 02点06分
level 1
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script type="text/javascript" src="js/jquery.min.js" ></script>
<script>
var i = 1;
$(document).ready(function(){
$("div").eq(0).show();
$("div").eq(1).hide();
$("div").eq(2).hide();
$("div").eq(3).hide();
var setin=window.setInterval(divtoggle,1000);
var setintwo;
$("div").hover(function(){
window.clearInterval(setin);
window.clearInterval(setintwo);
},function(){
setintwo=window.setInterval(divtoggle,1000);
})
})
function divtoggle(){
console.log(i);
if(i==4){i=0;}
console.log("a"+i+"a");
if(i==0){
$("div").eq(0).show();
$("div").eq(1).hide();
$("div").eq(2).hide();
$("div").eq(3).hide();
}
if(i==1){
$("div").eq(0).hide();
$("div").eq(1).show();
$("div").eq(2).hide();
$("div").eq(3).hide();
}
if(i==2){
$("div").eq(0).hide();
$("div").eq(1).hide();
$("div").eq(2).show();
$("div").eq(3).hide();
}
if(i==3){
$("div").eq(0).hide();
$("div").eq(1).hide();
$("div").eq(2).hide();
$("div").eq(3).show();
}
i++;
}
</script>
<style>
div{
width: 200px;
height: 200px;
}
</style>
</head>
<body>
<div style="background-color: aquamarine;"></div>
<div style="background-color: red;"></div>
<div style="background-color: deepskyblue;"></div>
<div style="background-color: gray;"></div>
</body>
</html>
2018年06月19日 02点06分
11
这下没bug了
2018年06月19日 02点06分