Javascript视差滚动效果在safari中不起作用

时间:2016-05-10 17:48:36

标签: javascript safari

这是一个用于创建视差滚动效果的脚本,并且导航栏从屏幕底部开始,并在向下滚动时粘到顶部。它在Firefox中完美运行。在Safari中,导航栏不可见,并且根本不滚动。任何帮助将不胜感激。

var header = document.getElementById("header");
var navBar = document.getElementById("navbar");
var bg = document.getElementById("bg");


var navbarHeight = navBar.offsetHeight;
var headerHeight = header.offsetHeight;

header.style.height = screen.height-navbarHeight;

function initParallax(){
    if(window.pageYOffset > headerHeight){
        navBar.style.position = "fixed";
        navBar.style.top = "0";
    }else{
        navBar.style.position = "absolute";
        navBar.style.top = "0";
    }
    bg.style.top = -(window.pageYOffset/10)+"px";

}

window.addEventListener("scroll", initParallax);

0 个答案:

没有答案