简体   繁体   English

取消粘贴在屏幕底部的div

[英]Unsticking a div that sticks to the bottom of the screen

Currently my sidebar, which is longer than the browser window, sticks to the bottom of the screen. 目前,我的侧边栏比浏览器窗口长,它固定在屏幕底部。 I need it to stop sticking to the bottom of the screen when the footer appears, so it doesn't cover the footer. 当页脚出现时,我需要它停止粘附在屏幕底部,因此它不会覆盖页脚。

I also want to make my header stick to the top of the screen, but not have the sidebar cover it. 我还想使标题保持在屏幕顶部,但没有侧边栏覆盖它。 It should be noted that I have tried using the hcsticky plugin for jQuery, but I can't get it to work at all. 应该注意的是,我已经尝试过将hcsticky插件用于jQuery,但是我根本无法使用它。

$(window).load(function(){ 

var $sidebar = $("#sidebar"),
$thefoot = $("#thefoot"),
$window = $(window),
offset = $sidebar.offset(),
sbBottom = Math.abs($window.height() - (offset.top + $sidebar.height())),
prevScrollTop = 0;

$window.scroll(function() {

if (prevScrollTop < $window.scrollTop()) {
    $sidebar.removeClass('fixedTop');
    if ($window.scrollTop() > (sbBottom + 12)) {
        $sidebar.addClass('fixedBtm');
    } else {
        $sidebar.removeClass('fixedBtm');
    }
} else {

    $sidebar.removeClass('fixedBtm');
    if ($window.scrollTop() > sbBottom) {
        $sidebar.addClass('fixedTop');
    } else {
        $sidebar.removeClass('fixedTop');
    }

} }); }});

}); });

#sidebar {
    width: 300px;
    margin-bottom: 10px;
    overflow: hidden;
    margin: 0 auto;
    float: left;
    clear: right;
}

.fixedBtm {
    margin-left: 660px !important;
    position: fixed;
    bottom: 0;
}

.fixedTop {
    margin-left: 660px !important;
    position: fixed;
    bottom: 0;
}

.footBtm {
    bottom: 350px;
}

#thefoot {
    background-color: #5774F2;
    clear: both;
    background-color: #ffffff;
    background-repeat: no-repeat;
    background-position: center;
    background-image: url("../images/footer.png");
    height: 340px;
    width: 100%;
}

I do not see the CSS, basically here is what are looking for based on the code you have presented. 我没有看到CSS,基本上是根据您提供的代码在寻找什么。

In CSS file, add these properties to the appropriate classes in addition to other properties you might have. 在CSS文件中,除了可能具有的其他属性外,还将这些属性添加到适当的类中。

/*for header element*/
.header{
  position:fixed;
  display: block;
  clear: both;
}

/*for footer element*/
.footer{
  display: block;
  clear: both;
}

/* for sidebar element*/
.sidebar{
  float:left;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM