固定层不随鼠标滚动
XML/HTML Code
- <div class="box">
- <!--代码开始-->
- <div class="main">拖动鼠标展示效果</div>
- <div class="sub">
- <div class="sub01"></div>
- <div class="sub01"></div>
- <div class="fixed">我是固定的哟freejs.net</div>
- </div>
- <!--代码结束-->
- </div>
JavaScript Code
- <script type="text/javascript">
- $(document).ready(function(e) {
- t = $('.fixed').offset().top;
- mh = $('.main').height();
- fh = $('.fixed').height();
- $(window).scroll(function(e){
- s = $(document).scrollTop();
- if(s > t - 10){
- $('.fixed').css('position','fixed');
- if(s + fh > mh){
- $('.fixed').css('top',mh-s-fh+'px');
- }
- }else{
- $('.fixed').css('position','');
- }
- })
- });
- </script>
原文地址:http://www.freejs.net/article_jquerywenzi_631.html