Skip to content

Commit 69ddea6

Browse files
add btn scroll up
1 parent 4f5b559 commit 69ddea6

File tree

4 files changed

+103
-1
lines changed

4 files changed

+103
-1
lines changed

css/style.min.css

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.html

+4
Original file line numberDiff line numberDiff line change
@@ -290,5 +290,9 @@ <h2 class="tours__title">POPULAR TOURS</h2>
290290
<p class="copyright">@2023 Adventure. All rights reserved</p>
291291
</div>
292292
</footer>
293+
<div class="scroll-up">
294+
<button class="button button__scroll">up</button>
295+
</div>
296+
<script src="./script.js"></script>
293297
</body>
294298
</html>

script.js

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const buttonToUp = document.querySelector(".button__scroll");
2+
3+
window.addEventListener("scroll", () => {
4+
if (window.pageXOffset > 200 || document.documentElement.scrollTop > 200) {
5+
buttonToUp.classList.add("visible");
6+
} else {
7+
buttonToUp.classList.remove("visible");
8+
}
9+
});
10+
11+
buttonToUp.addEventListener("click", () => {
12+
window.scrollTo({
13+
top: 0,
14+
behavior: "smooth",
15+
});
16+
});
17+
// $(window).scroll(function () {
18+
// if ($(window).scrollTop() > 300) {
19+
// btn.addClass("show");
20+
// } else {
21+
// btn.removeClass("show");
22+
// }
23+
// });
24+
25+
// btn.on("click", function (e) {
26+
// e.preventDefault();
27+
// $("html, body").animate({ scrollTop: 0 }, "300");
28+
// });

scss/_button.scss

+70
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,74 @@
1414
background: #f0aa21;
1515
padding: 18px 47px;
1616
}
17+
18+
&__scroll {
19+
width: 100px;
20+
height: 60px;
21+
22+
text-transform: uppercase;
23+
font-style: normal;
24+
font-weight: 800;
25+
font-size: 16px;
26+
line-height: 19px;
27+
text-align: center;
28+
letter-spacing: 0.135em;
29+
30+
color: #ffffff;
31+
border-radius: 84px;
32+
background: rgba(0, 0, 0, 0.2);
33+
border: 2px solid #fff;
34+
backdrop-filter: blur(8px);
35+
box-shadow: 0px 8px 15px rgba(0, 0, 0, 0.1);
36+
37+
transition: all 0.3s;
38+
39+
display: none;
40+
41+
&::before {
42+
content: "";
43+
border: solid #fff;
44+
border-width: 0 3px 3px 0;
45+
display: inline-block;
46+
padding: 3px;
47+
margin: 0 10px 0 0;
48+
49+
animation: arrow-up 2s infinite;
50+
51+
}
52+
53+
&:hover {
54+
background-color: #fff;
55+
color: #000;
56+
57+
&::before {
58+
border: solid #000;
59+
border-width: 0 3px 3px 0;
60+
}
61+
}
62+
}
63+
}
64+
65+
.scroll-up {
66+
position: fixed;
67+
margin: 100px;
68+
right: 0;
69+
bottom: 0;
70+
}
71+
.visible {
72+
display: block;
73+
}
74+
75+
@keyframes arrow-up {
76+
0% {
77+
opacity: 0;
78+
transform: rotate(-135deg) translate(-5px, -5px);
79+
}
80+
50% {
81+
opacity: 1;
82+
}
83+
100% {
84+
opacity: 0;
85+
transform: rotate(-135deg) translate(5px, 5px);
86+
}
1787
}

0 commit comments

Comments
 (0)