Sunday, 20 December 2020

scroll top/bottom of the screen on button click using Javascript not Jquery also It should work in chrome, IE & mozilla

I wanted to implement a simple top and bottom scroll on button click. the scroll should be smooth in all browsers.

Requirements -

I have two buttons on the page, on top of the page there is a button called Down on clicking on that It should go down to the footer div.

There is one more button on the bottom of the page called UP on clicking on that It should go up of the screen.

I have tried one solution but in IE, the scroll is not smooth. How can we make the scroll behaviour smooth in all browsers.

Currently I have used the scroll-behaviour property in css but is it a good practice? Is there any way to do it in Javascript instead of css?

html{
  scroll-behavior: smooth;
}

NOTE: It should also work in IE.

I would really appreciate your help.

Link of codepen for code- https://codepen.io/Akkanksha1/full/KKgWmgL



from scroll top/bottom of the screen on button click using Javascript not Jquery also It should work in chrome, IE & mozilla

No comments:

Post a Comment