我正在使用(window.innerwidth> 1025)来允许大于1025px宽的窗口中的视差代码。这适用于除Firefox之外的所有浏览器(Chrome,IE,Safari)。
当我删除第一行时,视差在Firefox中按预期工作。
if (window.innerWidth > 1025){
var $window = $(window);
var windowHeight = $(window).height();
var pos = $window.scrollTop(); //position of the scrollbar
var $this = $(this);
//setup defaults if arguments aren't specified
if(xpos == null){xpos = "50%"}
if(adjuster == null){adjuster = 0}
if(inertia == null){inertia = 0.1}
if(outerHeight == null){outerHeight = true}
height = $this.height();
$this.css({'backgroundPosition': newPos(xpos, outerHeight, adjuster, inertia)});
function newPos(xpos, windowHeight, pos, adjuster, inertia){
return xpos + " " + Math.round((-((windowHeight + pos) - adjuster) * inertia)) + "px";
}
//function to be called whenever the window is scrolled or resized
function move(pos, height){
$this.css({'backgroundPosition': newPos(xpos, height, pos, adjuster, inertia)});
}
$window.bind('scroll', function(){ //when the user is scrolling...
pos = $window.scrollTop(); //position of the scrollbar
inView(pos, $this);
})
}