javascript - 粘性侧边栏与页脚重叠?

标签 javascript jquery html css joomla

我已经为 ADS 创建了自定义的粘性侧边栏,它可以工作,但是有一个问题。当我将它滚动到底部时,它会重叠在页脚上。请检查。 - http://screencast.com/t/oEjcrbocB05C

var stickySidebar = $('.sticky');

if (stickySidebar.length > 0) { 
  var stickyHeight = stickySidebar.height(),
      sidebarTop = stickySidebar.offset().top;
}

// on scroll move the sidebar
$(window).scroll(function () {
  if (stickySidebar.length > 0) { 
    var scrollTop = $(window).scrollTop();
            
    if (sidebarTop < scrollTop) {
      stickySidebar.css('top', scrollTop - sidebarTop);

      // stop the sticky sidebar at the footer to avoid overlapping
      var sidebarBottom = stickySidebar.offset().top + stickyHeight,
          stickyStop = $('.main-content').offset().top + $('.main-content').height();
      if (stickyStop < sidebarBottom) {
        var stopPosition = $('.main-content').height() - stickyHeight;
        stickySidebar.css('top', stopPosition);
      }
    }
    else {
      stickySidebar.css('top', '0');
    } 
  }
});

$(window).resize(function () {
  if (stickySidebar.length > 0) { 
    stickyHeight = stickySidebar.height();
  }
});
.sticky {
  position: relative;
  top: 0; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

检查站点 URL 是 - http://www.test2.guru99.com/java-tutorial.html

请帮帮我!

最佳答案

修改你下面的CSS

#rt-footer-surround {
  background-color: #3f3f3f;
  color: #f8f8f8;
  text-shadow: 1px 1px 0 rgba(0, 0, 0, 0.1);
}

为此,添加 position:relativez-index:1

#rt-footer-surround {
  background-color: #3f3f3f;
  color: #f8f8f8;
  text-shadow: 1px 1px 0 rgba(0, 0, 0, 0.1);
  position: relative;
  z-index: 1;
}

关于javascript - 粘性侧边栏与页脚重叠?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38099951/

相关文章:

javascript - 通过使用 getElementsClassName、Javascript、DOM 的 ReplaceChild 访问 oldChild

javascript - PHP 中的 preg_match 或 javascript 中的类似函数

javascript - Javascript 中添加了哪些最新运算符?

javascript - 获取 <tr> 的第 n 个子元素

html - CSS 组织结构图水平线连接器

html - 如何将图像添加到网站超链接

javascript - Tinymce新线事件

javascript - 模拟双击拖动结束 - jquery UI

java - 通过 POST 使用 hibernate 和 vraptor 插入带有外键的实体

javascript - 获取输入范围以在页面加载时显示值,并提交 slider 值作为答案?