I have made a web page in React Js and one section as a lot of images which causes the scroll to run 1 fps making it a very bad user experience.
The scroll works well both on safari and chrome so I can't understand why Firefox is so slow? It seems that Firefox generally is bad at rendering a lot of images at once. I used this code from this solution Cross browser JavaScript (not jQuery...) scroll to top animation
css
margin: 20px 10px 0 10px;
width: 30%;
min-width: 300px;
background: #FFFFFF;
border-radius: 4px;
-webkit-box-shadow: 0px 5px 15px 0px rgba(70, 71, 76, 0.07);
box-shadow: 0px 5px 15px 0px rgba(70, 71, 76, 0.07);
overflow: hidden;
Below you can see the HTML is rendered.
The scroll function being used is used on many other pages and it works fine. If I remove the employee's node the scroll function works very well. Anybody with a hint why Firefox is so laggy while safari and chrome work very well?
scroll function
scrollTo(position) {
let scrollY = window.scrollY || document.documentElement.scrollTop,
scrollTargetY = position() || 0,
speed = 2000,
easing = 'easeInOutSine',
currentTime = 0
// min time .1, max time .8 seconds
let time = Math.max(.1, Math.min(Math.abs(scrollY - scrollTargetY) / speed, .8))
// easing equations from https://github.com/danro/easing-js/blob/master/easing.js
let easingEquations = {
easeOutSine: function (pos) {
return Math.sin(pos * (Math.PI / 2));
},
easeInOutSine: function (pos) {
return (-0.5 * (Math.cos(Math.PI * pos) - 1));
},
}
// add animation loop
function tick() {
currentTime += 1 / 60;
let p = currentTime / time;
let t = easingEquations[easing](p);
if (p < 1) {
requestAnimationFrame(tick);
window.scrollTo(0, scrollY + ((scrollTargetY - scrollY) * t));
} else {
window.scrollTo(0, scrollTargetY);
}
}
// call it once to get started
tick()
}
scroll function
you are talking about? Do you mean you have a scroll handler? You should post your code, or are you saying this is a problem with HTML only? Hard to tell what you are asking, consider improving your question. See stackoverflow.com/help/minimal-reproducible-example – Percaline