0

我想要一个小 div 贴在浏览器的右下角。这是我通过这样做完成的:

#div {
position: fixed;
bottom: 10px;
right: 10px;
}

但我有一个页脚,比如 height: 200px;。我想要的是,当你向下滚动页面时,div 停留在右下角,但是当页脚在页面底部弹出时,我希望页脚将其向上推,这样它就不会出现在前面页脚。

我希望我说清楚了...

4

2 回答 2

1

喜欢这可以在没有 jscripting 的情况下完成。:) 只需几行 CSS 和一些包装调整:http: //jsfiddle.net/bitofgrace/QGEUv/

<div id="wrapper">
<div id="flyover">hi</div> <!-- the content you want to stick in the corner -->
<div class="content"> Body of page content</div>

<div ID="footer"> FOOTER CONTENT</div>
</div> <!-- close wrapper -->

CSS

#wrapper {width:100%; height:100%; margin:0}
#flyover {background-color:pink; color:white; position:fixed; top: 87.5%; z-index:4;}
#footer {background:green; position:relative; height:100px; width:100%; bottom:0; z-index:1;}
于 2013-03-16T13:39:11.000 回答
1

我花了一段时间,但我想我已经为你找到了答案:)

您应该通过在添加 css 文件的行下方添加此行来将 JQuery 添加到 HTML:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>

然后创建一个文件scrollBottom.js(javascript文件),并像这样添加它:

<script src="scrollBottom.js" type="text/javascript"></script>

在该文件中添加以下代码(已编辑:应该添加 document.ready):

$(document).ready(function() {

    $(window).scroll(function() {
       if($(window).scrollTop() + $(window).height() > $(document).height()-200) {
           $('#div').css('bottom', $(window).scrollTop()-2360);
       }
        else
        {
            $('#div').css('bottom', '10px');
        }
    });​
});

工作示例:http: //jsfiddle.net/4VJtU/4/

于 2012-09-24T20:15:45.580 回答