tutsplus / javascript-for-web-designers

Source files to accompany Tuts+ course: JavaScript for Web Designers
BSD 2-Clause "Simplified" License
30 stars 32 forks source link

Back to top JS no longer works #1

Open AndrewSepic opened 4 years ago

AndrewSepic commented 4 years ago

Tried following along with the tutorial (on youtube) and the btt.addEventListener() click function for the back to top demo doesn't work in Chrome or safari. Tried downloading straight from github and the same result. What's changed 3 years?

ghost commented 2 years ago

The code is correct, the variable isFirefox checks if the browser is Firefox, you can follow the same steps and add 2 more variables for safari and google, then add it into the btt. addEventListener(), it will work just fine.

Already been 2 years since this question, so i doubt you will require an answer, but just in case a new developer comes to the same doubt, here is the solution.

RomeDomeYome commented 1 year ago

add these alongside isFirefox let isFirefox = navigator.userAgent.toLowerCase().indexOf("firefox") > -1, isChrome = navigator.userAgent.toLowerCase().indexOf("chrome") > -1, isSafari = navigator.userAgent.toLowerCase().indexOf("safari") > -1;

then change the if else statement to if (isFirefox || isChrome || isSafari) { docElem.scrollTop = 0; } else { body.scrollTop = 0; }