doutao5499 2014-09-22 16:18
浏览 7
已采纳

浮动框正在推动其他一切 - 无限滚动

So I add the box called "booking-picker" which is supposed to scroll down with you on the page -- but it pushes all the elements that are below him whatever they are. FYI bootstrap used. http://jsfiddle.net/2m849oes/ or Here is the script:

    <script>
    $(function() {

        var $sidebar   = $("#flow-picker"), 
            $window    = $(window),
            offset     = $sidebar.offset(),
            topPadding = 15

        $window.scroll(function() {
            if ($window.scrollTop() > offset.top) {
                $sidebar.stop().animate({
                    marginTop: $window.scrollTop() - offset.top + topPadding
                });
            } else {
                $sidebar.stop().animate({
                    marginTop: 0
                });
            }
        });

    });
</script>

And here is the html:

<div class="container">  
    <div class="row">BLABLABLABLABLA ........ 
    </div>
    <div class="booking-picker" id="flow-picker">
        <h3>Hello</h3>
        ETC......                    
    </div>    
</div>

And later I have the footer which is pushed down too.

And here is the CSS

.booking-picker {
  display: block;
  float: right;
}
#flow-picker {

}

Thanks!

  • 写回答

3条回答 默认 最新

  • doufen1890 2014-09-22 16:47
    关注

    I have used your fiddle from the question and updated it slightly for you here. what I have done is added some css to #flow-picker see below

    #flow-picker {
        position: fixed;
        top: 20px;
        right: 0;
        background: blue;
        color: white;
    }
    

    The background colour is just so you can see what is going on. When you use fixed position you need to specify a position using top, bottom, left and/or right properties. This tells the browser where to place it. They will be placed relative to the browser window.

    I removed your javascript because if this is what you are trying to achieve you can do it without javascript. Its normally better to try and use pure CSS for when it can be done using only CSS.

    I have made this fiddle which i have coloured to help show you how it works.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探