2010-11-12 101 views
0

我需要解决方案来模拟固定位置,但相对父母div,而不是整个视口。 JS解决方案是滞后的。我需要固定相关的父容器,因为如果窗口高度很小,则固定位置的div进入页脚区域。位置固定相关的父容器

Example

回答

2

您的更新的另一种方法。

先给固定divz-index: 10;

和页脚DIV position: relative; z-index: 11

这应该使页脚重叠固定股利。

+0

嗯,这是很好的解决方案,但我想停止附件页脚附近的滚动。 – INs 2010-11-12 18:05:36

+1

@INs绝对不可能没有Javascript。 – 2010-11-12 18:11:42

+0

也许你知道JS平滑滚动的好解决方案,作为固定位置? jquery插件scrollfollow是laggy。 – INs 2010-11-13 07:23:38

0

那就不是位置问题:固定的,也许你可以只定义一个最小高度,你的身体(或主包装如果有的话),以避免短期页面问题

+0

我已经添加了示例我的意思 – INs 2010-11-12 17:57:26

0

我已经合并CSS和JS:

$(document).ready(function() { 
       var $sidebar = $(".register-box"), 
       $window = $(window), 
       $content = $("#content"), 
       docHeight = $(document).height(); 
       var entered = false; 

       $window.scroll(function() { 
        if ($window.height() < 795 && docHeight - $window.scrollTop() < 785) { 
         entered = true; 
         var pos = $sidebar.offset(); 
         $sidebar.css('position', 'absolute').css('top', ($content.height() - ($sidebar.height() + 40)) + 'px'); 
        } 
        else { 
         if (entered) { 
          entered = false; 
          $sidebar.css({ 
           top: "", 
           left: "", 
           position: "fixed" 
          }); 
         } 
        } 
       }); 
      }); 

代码不是最终版本,和数字是硬编码的,但它的工作原理,不够顺畅。