I have an element I'm applying some basic transitions to based on scroll position. It works smoothly as expected in Safari and Firefox, but scrolling in Chrome is very choppy.
$(document).ready(function($) {
var divUp = $('.fade');
var divDown = $('.fade-down');
$(window).on('scroll', function() {
var st = $(this).scrollTop();
divUp.css({
'top' : -(st/6)+"px",
'opacity' : 1 - st/400
});
divDown.css({
'opacity' : 1 - st/400
});
});
});
I commented out each CSS
property individually, but Chrome is choppy either way. The top
property is moving a relatively positioned element.
How can I achieve the desired effect while still making Chrome's JS engine happy? Thanks in advance for any feedback.