-
Notifications
You must be signed in to change notification settings - Fork 2
/
top-button.php
68 lines (62 loc) · 2.03 KB
/
top-button.php
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
<head>
<style>
#myButton {
display: none;
position: fixed;
bottom: 20px;
right: 30px;
z-index: 99;
border: none;
outline: none;
color: white;
cursor: pointer;
padding: 15px;
border-radius: 4px;
background: #38d986;
background-image: -webkit-linear-gradient(top, #38d986, #22a12b);
background-image: -moz-linear-gradient(top, #38d986, #22a12b);
background-image: -ms-linear-gradient(top, #38d986, #22a12b);
background-image: -o-linear-gradient(top, #38d986, #22a12b);
background-image: linear-gradient(to bottom, #38d986, #22a12b);
-webkit-border-radius: 47;
-moz-border-radius: 47;
border-radius: 47px;
font-size: 25px;
padding: 10px 20px 10px 20px;
text-decoration: none;
opacity: 0.7;
}
#myButton:hover {
background: #0d6b0a;
background-image: -webkit-linear-gradient(top, #0d6b0a, #1da13a);
background-image: -moz-linear-gradient(top, #0d6b0a, #1da13a);
background-image: -ms-linear-gradient(top, #0d6b0a, #1da13a);
background-image: -o-linear-gradient(top, #0d6b0a, #1da13a);
background-image: linear-gradient(to bottom, #0d6b0a, #1da13a);
text-decoration: none;
}
</style>
</head>
<body>
<button onclick="topFunction()" id="myButton" title="Go to top"><strong>🡅</strong></button>
<script>
// Get the button
let mybutton = document.getElementById("myButton");
// When the user scrolls down 20px from the top of the document, show the button
window.onscroll = function() {
scrollFunction()
};
function scrollFunction() {
if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
mybutton.style.display = "block";
} else {
mybutton.style.display = "none";
}
}
// When the user clicks on the button, scroll to the top of the document
function topFunction() {
document.body.scrollTop = 0;
document.documentElement.scrollTop = 0;
}
</script>
</body>