2012-08-24 50 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'}); 
    }); 
});