$("body").scrollTop()在Safari中不会更新 [英] $("body").scrollTop() doesn't update in safari

查看:92
本文介绍了$("body").scrollTop()在Safari中不会更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在一个网站上

http://beta.projektopia.se/

身体有几个背景图像,这些背景图像会像这样滚动更新:

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);
    });
});

很多计算,但重要的是创建了一个滚动位置,该滚动位置应在滚动时更改背景的位置,以创建视差效果.它在chrome中效果很好,但在firefox中,假定要获取当前滚动位置的变量scrollfactor不会更新.

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,由于缺少正确的文档类型,有些人遇到了这个问题.我相信我已经这样正确地声明了:

ps, some people have this issue due to lack of correct doctype. I believe i have declared it correctly like this:

<!DOCTYPE html>

推荐答案

已知scrollTop jQuery方法有问题.

The scrollTop jQuery method has been known to be problematic.

取决于浏览器,可能需要使用$('html, body').scrollTop()$(document).scrollTop()$(window).scrollTop().

Depending on the browser, you may need to use $('html, body').scrollTop() or $(document).scrollTop() or $(window).scrollTop().

这篇关于$("body").scrollTop()在Safari中不会更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆