如何在固定侧边栏中添加填充/边距底部?

时间:2015-07-10 15:41:49

标签: javascript jquery css

我已成功设置了tutorial之后的固定滚动侧边栏。

我唯一遇到的问题是在侧边栏底部添加填充/边距。目前它与视口底部齐平,我希望它可以说是100px;从底部开始。

我不确定是否需要编辑JS,或者这是否可以通过CSS实现?

继承我的Demo

JS

$(function () {

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

  if (!msie6 && $('.sidebar-container').offset()!=null) {
    var top = $('.sidebar-container').offset().top - parseFloat($('.sidebar-container').css('margin-top').replace(/auto/, 0));
    var height = $('.sidebar-container').height();
    var winHeight = $(window).height(); 
    var footerTop = $('#footer').offset().top - parseFloat($('#footer').css('margin-top').replace(/auto/, 0));
    var gap = 7;
    $(window).scroll(function (event) {
      // what the y position of the scroll is
      var y = $(this).scrollTop();

      // whether that's below the form
      if (y+winHeight >= top+ height+gap && y+winHeight<=footerTop) {
        // if so, ad the fixed class
        $('.sidebar-container').addClass('leftsidebarfixed').css('top',winHeight-height-gap +'px');

0 个答案:

没有答案
相关问题