-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSCROLL-PRACTICE.html
More file actions
68 lines (63 loc) · 1.63 KB
/
Copy pathSCROLL-PRACTICE.html
File metadata and controls
68 lines (63 loc) · 1.63 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
58
59
60
61
62
63
64
65
66
67
68
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<style type="text/css" media="all">
body {
display: grid;
place-content: center;
gap: 2rem;
}
.cont {
height: 300px;
width: 300px;
background: #333;
display: flex;
overflow: scroll;
transition: all 2s;
}
.card {
width: 100%;
height: 100%;
background: #444;
border: 2px solid yellow;
flex-shrink: 0;
transition: all 1s ease;
}
.card:nth-child(2) {
background: yellow;
}
</style>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Div</title>
</head>
<body>
<div class="cont">
<div class="card"></div>
<div class="card active"></div>
<div class="card"></div>
<div class="card"></div>
</div>
<button id="button">Scroll left</button>
</body>
<script type="text/javascript" charset="utf-8">
// Find the target div with the "active" class
var targetDiv = document.querySelector(".active");
const button = document.getElementById("button");
button.onclick = scroll;
let length = 0;
let scrollToEnd = false;
const cont = document.querySelector(".cont");
console.log(cont.children)
let arr = cont.children
Array.from(arr).forEach(function (i, ind) {
setTimeout(() => {
i.scrollIntoView({
behavior: "smooth",
})
},ind * 3000)
})
// Scroll to the target div
console.log(cont.scrollWidth);
</script>
</html>