2012-08-24 63 views
0

我试图让这个.side_content_wrapper根据用户向下滚动页面和备份它的程度变得固定或静态。我已经在IE8 +/chrome/firefox中正常工作了。但由于某些原因,我无法在IE7中使用它。难道我做错了什么?IE7中的JQuery固定滚动问题

感谢您的帮助!

$(window).scroll(function(e){ 

var scrollAmount = $(window).scrollTop(); 
var documentHeight = $(document).height(); 
var heightFromBottom = documentHeight - scrollAmount; 
$el = $('.side_content_wrapper'); 

if((scrollAmount > 320 && heightFromBottom > 950) && $el.css('position') != 'fixed') { 
    fixToScroll();} 

else if (scrollAmount < 320 && $el.css('position') == 'fixed') { 
    fixToStatic();} 

if(heightFromBottom <= 950 && $el.css('position') == 'fixed') { 
    fixToBottom();} 

else if((heightFromBottom > 950 && scrollAmount > 320) && $el.css('position') == 'fixed') { 
    fixToScroll();} 


function fixToScroll() { 
    $('.side_content_wrapper').css({'position': 'fixed', 'top': '35px', 'right': '218px'}); 
} 
function fixToStatic() { 
    $('.side_content_wrapper').css({'position': 'static', 'top': '0px', 'right': '0px'}); 
} 
function fixToBottom() { 
    $('.side_content_wrapper').css({'position': 'fixed', 'bottom': '400px', 'top': 'inherit', 'right': '218px'}); 
} 
}); 
+0

哪一部分无法正常工作?滚动距离检测或位置变化?你有任何错误? – MrOBrian

+0

我试着用IE开发工具进行调试,并且没有遇到任何错误。我认为我的某些地方IE语法错误的地方有些语法错误。直到到达页面底部,它才会检测距离,然后更改位置。 – user1623479

+0

检查你的文档模式,以确保你在IE7标准(而不是怪癖模式或兼容模式或MS决定扔在那里的任何其他愚蠢的事情)。我已经读过'位置:固定'在IE7中的一个小错误,这取决于浏览器所处的模式。 – MrOBrian

回答

0

我想通了:

$(document).ready(function() { 
    var div = $('.fixed_floater'); 
    var offset = div.offset(); 
    var top = offset.top; 
    $(window).scroll(function() { 
     var heightFromBottom = $(document).height() - $(window).scrollTop(); 
     var y = $(this).scrollTop(); 

     if (y >= top && heightFromBottom > 950) { 
      div.css({'position': 'fixed', 'top': '0px'}); 
     } else { 
      div.css({'position': 'static'}); 
     } 

     if (heightFromBottom <= 950) 
      div.css({'position': 'fixed', 'bottom': '390px', 'top': 'auto'}); 
    }); 
});