DEV Community

Discussion on: Scroll to top button with JQuery

Collapse
 
eshimischi profile image
eshimischi • Edited

This. ScrollIntoView (smooth) still in need of polyfill for legacy browsers tho

Collapse
 
atulcodex profile image
🚩 Atul Prajapati 🇮🇳

okay will do it

Collapse
 
Sloan, the sloth mascot
Comment deleted
 
atulcodex profile image
🚩 Atul Prajapati 🇮🇳

okay why not

Thread Thread
 
eshimischi profile image
eshimischi

Well yes, but better add this one jsdelivr.com/package/npm/smoothscr... and use ScrollIntoView

Thread Thread
 
frankwisniewski profile image
Frank Wisniewski

write your own Polyfill..

scrollMe = () => {
          if ( document.querySelector( 'body' ).scrollIntoView ){
            document.querySelector( 'body' )
              .scrollIntoView( { behavior: 'smooth' } )
          } else {
            let diff = document.documentElement.scrollTop || document.body.scrollTop;
            if (diff > 0) {
              window.requestAnimationFrame(scrollMe);
              window.scrollTo(0, diff - diff / 6);
            }
          }
        }
Enter fullscreen mode Exit fullscreen mode