Open AndrewSepic opened 4 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.
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; }
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?