我试图根据用户向下滚动页面并备份它的程度,使.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'});
}
});
答案 0 :(得分: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'});
});
});