Making a Back to the Top button on Javascript

12 Views Asked by At

I tried making a button that returns you to the top when you click it, and it disappears whenever youre at the top

So can somebody please fix this for me, its due monday and is still have alot to finsih on this project its a school project, and its not that easy to find a tutorial about it, and if I do find one, I dont think the videos gonna be enough to explain what was happening on the code.

So I want that if I leave window.scrollY 0, An element with 'start' ID will have the class 'start_nav', so basically it adjusts the opacity and scale so its visible when u get out of header (window.scrollY 0), and then when u go back to the header, that 'start' ID element's class will be changed into 'start_nav_close' basically making it disppear because I dont need a "go back to top button" anymore because im already at the top

{
  if (window.scrollY == 0) {
    document.getElementById('start').classList = "start_nav_close";
  }
  else {
    document.getElementById('start').classList = "start_nav";
  
  }
}
0

There are 0 best solutions below