I have a jQuery function that changes the property of background-position
three elements to mousemove
, and this seems to cause some performance issues.
It should be noted that the background images of these elements are SVG.
Code example:
$(window).on('mousemove', function(event) {
window.requestAnimationFrame(function() {
$banner.find('.pattern').each(function(key) {
var modifier = 20 * (key + 1);
$(this).css({
'background-position': (event.pageX / modifier)+'px '+(event.pageY / modifier)+'px'
});
});
});
});
See my working code here: https://codepen.io/thelevicole/project/full/DarVMY/
I use window.requestAnimationFrame()
, and I also have a will-change: background-position;
css attribute for each element.
As you can probably tell, this effect is lagging behind. Large windows seem to be getting worse.
I am sure the problem is with using SVG for background images instead of PNG. The reason I use SVG is because of the high pixel density screens.
- , FPS, PNG, . .