$("body").scrollTop() doesn't update in safari
Posted
by
Kristoffer Nolgren
on Stack Overflow
See other posts from Stack Overflow
or by Kristoffer Nolgren
Published on 2012-11-04T14:57:27Z
Indexed on
2012/11/04
17:00 UTC
Read the original article
Hit count: 210
JavaScript
|jQuery
I'm working on a website:
the body has several background-images that are updated on scroll like this:
$(document).ready(function(){
$(document).scroll(function(){
var scrollfactor=$("body").scrollTop()*0.2;
var centerscrollpos =scrollfactor+613;
var docheight = $(document).height();
var windowheight = $(window).height();
var bottompos = (docheight-980)-((docheight-windowheight)*0.2)+scrollfactor;
var scrollpos = 'center '+scrollfactor+'px,center '+bottompos+'px, center '+ centerscrollpos+'px,center 0px';
$("body").css("background-position", scrollpos);
});
});
Lots of calculations, but the important thing is that a scrollpos is created that should change the position of the background when you scroll, to create a parallax-effect. It works great in chrome, but in firefox, the variable scrollfactor, that is suppose to get the current scroll-position, doesn't update.
ps, some people have this issue due to lack of correct doctype. I believe i have declared it correctly like this:
<!DOCTYPE html>
© Stack Overflow or respective owner