HTML, CSS, Bootstrap, XML, ajax, react js, WordPress, Magento, Shopify, Photoshop, Camtasia, SEO & learning new skills every moment ๐จ๐ผโ๐ป | I believe in learning and sharing with others ๐ด
HTML, CSS, Bootstrap, XML, ajax, react js, WordPress, Magento, Shopify, Photoshop, Camtasia, SEO & learning new skills every moment ๐จ๐ผโ๐ป | I believe in learning and sharing with others ๐ด
HTML, CSS, Bootstrap, XML, ajax, react js, WordPress, Magento, Shopify, Photoshop, Camtasia, SEO & learning new skills every moment ๐จ๐ผโ๐ป | I believe in learning and sharing with others ๐ด
constBUTTON_ID='topBtn';constDURATION_NAME='--fade-duration';constSHOW_BUTTON='topBtn';constSCROLL_DURATION=300;constSCROLL_CYCLE=15;functioninitialize(_event){constbutton=document.getElementById(BUTTON_ID);constshowButton=(_event)=>{if(window.scrollY>40)button.classList.add(SHOW_BUTTON);elsebutton.classList.remove(SHOW_BUTTON);};constscrollTarget=window;constscrollToTop=(event)=>{lety=window.scrollY;constx=window.scrollX;conststep=Math.floor((y*SCROLL_CYCLE)/SCROLL_DURATION);constnextStep=()=>{y=step<y?y-step:0;window.scrollTo(x,y);if(y>0){setTimeout(nextStep,SCROLL_CYCLE);return;}scrollTarget.focus();};event.target.blur();nextStep();};// Enable animation after everything is loadedconstrootStyle=getComputedStyle(document.documentElement);constduration=rootStyle.getPropertyValue(DURATION_NAME);button.style.setProperty(DURATION_NAME,duration);document.addEventListener('scroll',showButton);button.addEventListener('click',scrollToTop);}if(document.readyState==='loading')document.addEventListener('DOMContentLoaded',initialize);elseinitialize();
HTML, CSS, Bootstrap, XML, ajax, react js, WordPress, Magento, Shopify, Photoshop, Camtasia, SEO & learning new skills every moment ๐จ๐ผโ๐ป | I believe in learning and sharing with others ๐ด
A few years ago I realized it as a plugin in vanilla.js
insert the following line before the closing body tag:
<script data-color=blue src="scrolltotop.js"></script>
The file scrolltotop.js:
This. ScrollIntoView (smooth) still in need of polyfill for legacy browsers tho
okay why not
Well yes, but better add this one jsdelivr.com/package/npm/smoothscr... and use ScrollIntoView
write your own Polyfill..
okay will do it
Oh that's great, I don't know about this. Thank you very much for sharing :)
You donโt need jQuery, try to make the same task with vanilla js
The implementation seen is JQuery dependant, but I do agree that a Vanilla JavaScript implementation would've been more interesting.
Another stab at vanilla:
Modify:
Modify:
Replace:
Nice Work!
Thanks ๐ dear โบ๏ธ