-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
84 lines (82 loc) · 2.26 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<style>
.keJi{
width: 300px;
height: 200px;
overflow: hidden;
margin:100px auto;
margin-bottom: 0px;
}
.images{
height: 200px;
width: 1200px;
display: flex;
transition: all 1s;
}
.images>img{
width: 300px;
height: 200px;
}
.buttons{
text-align: center;
}
.buttons>span{
border: 1px solid red;
}
.red{
color: red;
}
</style>
</head>
<body>
<div class="keJi" id="keJi">
<div class="images">
<img src="images/1.jpg" alt="">
<img src="images/2.jpg" alt="">
<img src="images/3.jpeg" alt="">
<img src="images/01569658d947b2a801219c77dbcf7e.jpg@1280w_1l_2o_100sh.jpg" alt="">
</div>
</div>
<div class="buttons">
<span id="btn" class="red">图片1</span>
<span id="btn">图片2</span>
<span id="btn">图片3</span>
<span id="btn">图片4</span>
</div>
</body>
<script>
var allbuttons=$(".buttons>#btn");
for(var i=0;i<allbuttons.length;i++){
$(allbuttons[i]).on("click",function(x){
var btnindex=$(x.currentTarget).index();
index1=btnindex
redButton($(allbuttons).eq(index1));
$(".images").css({transform:"translateX("+btnindex*-300+"px)"})
})
}
index1=0;
buttonTrigger();
$(".keJi").on("mouseenter",function(){
window.clearInterval(timer);
})
$(".keJi").on("mouseleave",function(){
buttonTrigger();
})
function buttonTrigger(){
timer=setInterval(()=>{
index1++;
$(allbuttons).eq(index1%4).trigger("click")
},2000)
}
function redButton($button){
$button.addClass("red").siblings(".red").removeClass("red");
}
</script>
</html>