first commit
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
<div class="back">🡄</div>
|
||||
<button onclick="topFunction()" id="topBtn" title="Go to top">🡅</button>
|
||||
|
||||
<script>
|
||||
let topButton = document.getElementById("topBtn");
|
||||
|
||||
window.onscroll = function() {scrollFunction()};
|
||||
|
||||
function scrollFunction() {
|
||||
if (document.body.scrollTop > 80 || document.documentElement.scrollTop > 80) {
|
||||
topButton.style.display = "block";
|
||||
} else {
|
||||
topButton.style.display = "none";
|
||||
}
|
||||
}
|
||||
|
||||
function topFunction() {
|
||||
document.body.scrollTop = 0;
|
||||
document.documentElement.scrollTop = 0;
|
||||
}
|
||||
|
||||
var back = document.querySelector(".back");
|
||||
|
||||
window.addEventListener('pageshow', (event) => {
|
||||
event.preventDefault();
|
||||
if(window.location.hash != ""){
|
||||
console.log('#');
|
||||
setTimeout(function(){
|
||||
var id = window.location.href.split("#")[1];
|
||||
document.getElementById(id).scrollIntoView({behavior: "smooth", block: "start", inline: "nearest"});
|
||||
},100);
|
||||
}
|
||||
}, false);
|
||||
|
||||
if(window.location.pathname.split('/').pop() != "index.html"){
|
||||
back.style.display = "block";
|
||||
back.addEventListener("click", function(){
|
||||
if(window.history.length >=2){
|
||||
window.history.back();
|
||||
//window.history.go(-1);
|
||||
}else{
|
||||
window.location.href = "../../index.html";
|
||||
};
|
||||
});
|
||||
};
|
||||
</script>
|
||||
Reference in New Issue
Block a user