JQuery修复了IE7中的滚动问题



我正试图根据用户向下滚动页面和备份页面的距离,使此.side_content_wrapper变为固定或静态。我在IE8+chrome/firefox中可以很好地工作。但由于某种原因,我无法在IE7中使用它。我做错什么了吗?

谢谢你的帮助!

$(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'}); 
}
});

我发现了:

$(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'});
    });
});

最新更新