当滚动条滑到某一部分以后那一部分的横条就停靠在浏览器顶端,例如http://tuan.newegg.com.cn/里“团购筛选”所在横条,求解!!!!!!!!!!!!!!!!!!!!!!!!浏览器js

解决方案 »

  1.   

    用的是fixed定位,你在ie6下看看这个东东不好使.fixpos{position:fixed!important;top:-11px;width:970px;_position:absolute!important;_left:0!important;_top:expression(documentElement.scrollTop-document.getElementById('header').offsetHeight-25>0?documentElement.scrollTop-document.getElementById('header').offsetHeight-25:0);}
      

  2.   

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>无标题文档</title>
        <script src="Scripts/jquery-1.9.1.min.js"></script>
        <style>
            .box
            {
                position: absolute;
                width: 100px;
                height: 20px;
                background: #ccc;
            }
        </style>
    </head><body>
        <div style="height: 200px; background: blue;">1111111111111111111</div>    <div class="box" id="box">心随你动</div>    <div style="height: 1400px; background: green; margin-top: 40px;"></div>
        <script>
            $(function () {
                $(window).scroll(function () {                var top = $(this).scrollTop();
                    if (top > 200) {
                        var space = $("#box").scrollTop();
                        $("#box").css("top", space + "px");
                        var height = document.documentElement.scrollTop + document.body.scrollTop + space;
                        var top1 = parseInt($("#box").css("top"));
                        $("#box").css("top", parseInt(height - top1));
                    } else {
                        $("#box").css("top", 200);
                    }
                });
            })
        </script>
    </body>
    </html>
      

  3.   

    下面这个好点,上面那个效果是实现 了,但是代码有点乱。<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>无标题文档</title>
        <script src="Scripts/jquery-1.9.1.min.js"></script>
        <style>
            .box
            {
                position: absolute;
                width: 100px;
                height: 20px;
                background: #ccc;
            }
        </style>
    </head><body>
        <div style="height: 200px; background: blue;">1111111111111111111</div>    <div class="box" id="box">心随你动</div>    <div style="height: 1400px; background: green; margin-top: 40px;"></div>
        <script>
            $(function () {
                $(window).scroll(function () {
                    var top = $(this).scrollTop();
                    if (top > 200) {
                        $("#box").css("top", 0);
                        $("#box").css("top",top);
                    } else {
                        $("#box").css("top", 200);
                    }
                });
            })
        </script>
    </body>
    </html>
      

  4.   

    3#方法应该可以的,没实现估计是你的jquery路径不对
      

  5.   

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>无标题文档</title>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
        <style>
            .box
            {
                position: absolute;
                width: 100px;
                height: 20px;
                background: #ccc;
            }
        </style>
    </head>
     
    <body>
        <div style="height: 200px; background: blue;">1111111111111111111</div>
     
        <div class="box" id="box">心随你动</div>
     
        <div style="height: 1400px; background: green; margin-top: 40px;"></div>
        <script>
            $(function () {
                $(window).scroll(function () {
                    var top = Math.max($(document.body).scrollTop(), $(document.documentElement).scrollTop());
                    if (top > 200) {
                        $("#box").css("top",top);
                    } else {
                        $("#box").css("top", 200);
                    }
                });
            })
        </script>
    </body>
    </html>可兼容ie