-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
62 lines (56 loc) · 2.31 KB
/
index.html
File metadata and controls
62 lines (56 loc) · 2.31 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>Smooth scroll - By raylissonx404</title>
<link rel="icon" href="https://files.catbox.moe/xut16i.ico" type="image/x-icon"/>
<link rel="stylesheet" href="css/style.css" type="text/css"/>
</head>
<body>
<main>
<section id="section1">
<h2>This is Section 1</h2>
<div class="botoesArea">
<button class="btn2">Go to Section 2</button>
<button class="btn3">Go to Section 3</button>
</div>
</section>
<section id="section2">
<h2>This is Section 2</h2>
<div class="botoesArea">
<button class="btn1">Go to Section 1</button>
<button class="btn3">Go to Section 3</button>
</div>
</section>
<section id="section3">
<h2>This is Section 3</h2>
<div class="botoesArea">
<button class="btn1">Go to Section 1</button>
<button class="btn2">Go to Section 2</button>
</div>
</section>
</main>
<script>
[
{ trigger: ".btn1", target: "section1", offset: 0, speed: 1000 },
{ trigger: ".btn2", target: "section2", offset: 0, speed: 1000 },
{ trigger: ".btn3", target: "section3", offset: 0, speed: 1000 }
].forEach(({ trigger, target, offset, speed }) => {
document.querySelectorAll(trigger).forEach(button => {
button.addEventListener("click", () => {
const start = window.scrollY,
end = document.getElementById(target).offsetTop - offset,
t0 = performance.now();
requestAnimationFrame(function step(t) {
const p = Math.min((t - t0) / speed, 1),
e = p < .5 ? 2 * p * p : 1 - Math.pow(-2 * p + 2, 2) / 2;
window.scrollTo(0, start + (end - start) * e);
if (p < 1) requestAnimationFrame(step);
});
});
});
});
</script>
</body>
</html>