底部固定浮动侧边栏

时间:2011-04-21 04:26:57

标签: javascript

我一直在使用这个固定的浮动侧边栏(http://jqueryfordesigners.com/fixed-floating-elements/)。这很有效,我唯一的问题是我不知道如何强制降低底部,因此固定定位永远不会比可视区域高。我的侧边栏可以添加内容,有时候当侧边栏从底部的页面延伸出来时会有很多内容。有人能朝正确的方向射击我吗?这是侧边栏的javascript。

  var msie6 = $.browser == 'msie' && $.browser.version < 7;

  if (!msie6) {
    var top = $('#comment').offset().top - parseFloat($('#comment').css('margin-top').replace(/auto/, 0));
    $(window).scroll(function (event) {
  // what the y position of the scroll is
  var y = $(this).scrollTop();

  // whether that's below the form
  if (y >= top) {
    // if so, ad the fixed class
    $('#comment').addClass('fixed');
  } else {
    // otherwise remove it
    $('#comment').removeClass('fixed');
  }
});

}
});

2 个答案:

答案 0 :(得分:0)

$('#comment').css({'overflow-y':'scroll', max-height:'100%'});

答案 1 :(得分:0)

如果你的意思是注释应该只在一个范围内浮动(由它的高度确定),那么你可能想看看这篇文章: Fixed Floating Sidebar

请参阅奖金部分。

相关问题