0

我正在尝试根据用户向下滚动页面并备份它的距离使这个 .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'}); 
}
});
4

1 回答 1

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'});
    });
});
于 2012-08-29T13:36:46.503 回答