Skip to main content

How To Create a Scroll To Top Button in php?

 Create a Scroll To Top Button



<html>
<head>



<script>
// 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 >500|| document.documentElement.scrollTop >500) {
    document.getElementById("myBtn").style.display = "block";
  } else {
    document.getElementById("myBtn").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>
<style>

#myBtn {
  display: none;
  position: fixed;
  bottom: 20px;
  right: 30px;
  z-index: 99;
  font-size: 18px;
  border: none;
  outline: none;
  background-color:#EAC159;
  color: white;
  cursor: pointer;
  padding: 15px;
  border-radius:50%;
  opacity: 0.5;
}

#myBtn:hover {
  background-color: #555;
}
.red{
color:red;
}



</style>
<head>
<body>

<button onclick="topFunction()" id="myBtn" title="Go to top">Top</button>



<h1 class="red" >hello man how are you</h1>
<h1>hello man how are you</h1>
<h1>hello man how are you</h1>
<h1>hello man how are you</h1>
<h1>hello man how are you</h1>
<h1>hello man how are you</h1>
<h1>hello man how are you</h1>
<h1>hello man how are you</h1>
<h1>hello man how are you</h1>
<h1>hello man how are you</h1>
<h1>hello man how are you</h1>
<h1>hello man how are you</h1>
<h1>hello man how are you</h1>
<h1>hello man how are you</h1>
<h1>hello man how are you</h1>
<h1>hello man how are you</h1>
<h1>hello man how are you</h1>
<h1>hello man how are you</h1>
<h1>hello man how are you</h1>
<h1>hello man how are you</h1>
<h1>hello man how are you</h1>
<h1>hello man how are you</h1>
<h1>hello man how are you</h1>
<h1>hello man how are you</h1>
<h1>hello man how are you</h1>
<h1>hello man how are you</h1>
<h1>hello man how are you</h1>
<h1>hello man how are you</h1>
<h1>hello man how are you</h1>
<h1>hello man how are you</h1>
<h1>hello man how are you</h1>
<h1>hello man how are you</h1>
<h1>hello man how are you</h1>
<h1>hello man how are you</h1>
<h1>hello man how are you</h1>
<h1>hello man how are you</h1>
<h1>hello man how are you</h1>
<h1>hello man how are you</h1>
<h1>hello man how are you</h1>
<h1>hello man how are you</h1>
<h1>hello man how are you</h1>
<h1>hello man how are you</h1>
<h1>hello man how are you</h1>
<h1>hello man how are you</h1>
<h1>hello man how are you</h1>
<h1>hello man how are you</h1>
<h1>hello man how are you</h1>
<h1>hello man how are you</h1>
<h1>hello man how are you</h1>
<h1>hello man how are you</h1>
<h1>hello man how are you</h1>
<h1>hello man how are you</h1>
<h1>hello man how are you</h1>
<h1>hello man how are you</h1>
<h1>hello man how are you</h1>
<h1>hello man how are you</h1>

<h1>hello man how are you</h1>
<h1>hello man how are you</h1>
<h1>hello man how are you</h1>
<h1>hello man how are you</h1>
</body>

</html>

Comments

Popular posts from this blog

How to check date format in PHP?

Check date format in PHP function isCorrectDateFromat($date){     if(!empty($date)){         $dateString = $date; // Replace this with your date string         $format = "Y-m-d"; // Replace this with your expected date format         $dateTime = DateTime::createFromFormat($format, $dateString);         if ($dateTime === false) { /*             echo "The date is not in the correct format."; */         } else {             $errors = DateTime::getLastErrors();             if (empty($errors)) { /*                 echo "The date is in the correct format."; */                 return true;             } else { /*                 echo "...