-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path85.html
More file actions
57 lines (54 loc) · 2.09 KB
/
85.html
File metadata and controls
57 lines (54 loc) · 2.09 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>hover滚动</title>
<style>
.card {
white-space: nowrap;
overflow-x: scroll;
line-height: 200px;
background-color: blueviolet;
}
</style>
</head>
<body>
<p class="card">
云想衣裳花想容,春风拂槛露华浓。云想衣裳花想容,春风拂槛露华浓。云想衣裳花想容,春风拂槛露华浓。云想衣裳花想容,春风拂槛露华浓。云想衣裳花想容,春风拂槛露华浓。云想衣裳花想容,春风拂槛露华浓。云想衣裳花想容,春风拂槛露华浓。云想衣裳花想容,春风拂槛露华浓。云想衣裳花想容,春风拂槛露华浓。云想衣裳花想容,春风拂槛露华浓。
</p>
</body>
<script>
var timer = null;
let p = document.querySelector(".card");
p.addEventListener("mouseenter", function (e) {
let that = this;
const mouseX = e.offsetX;
// scrollLeft:dom的已滚动宽度 、offsetWidth:dom的视区宽度 、scrollWidth:dom的可滚动宽度
if (mouseX > (that.offsetWidth / 2)) {
timer = setTimeout(function fn() {
if ((that.scrollLeft + that.offsetWidth) == that.scrollWidth) {
clearTimeout(timer);
} else {
timer = setTimeout(fn, 100);
}
that.scrollLeft += 10;
}, 100);
} else {
timer = setTimeout(function fn() {
if (!that.scrollLeft) {
clearTimeout(timer);
} else {
timer = setTimeout(fn, 100);
}
that.scrollLeft -= 10;
}, 100);
}
});
p.addEventListener("mouseleave", function (e) {
clearTimeout(timer);
});
</script>
<script src="../js/front_next.js" type="text/javascript" charset="utf-8"></script>
</html>