日期:2014-05-16  浏览次数:20395 次

导航条随滚动条上下滚动
导航条随滚动条上下滚动,就像美丽说的导航条一样。没办法,本人js太差,望前辈告知

------解决方案--------------------
HTML code

<!DOCTYPE HTML>
<html>
    <head>
        <meta charset="gb2312" />
        <title></title>
        <style>
            body {
                height:2000px;
            }
            div {
                position:absolute; right:40px; top:40px;
                width:90%; height:30px;
                background:#ddd;
            }
        </style>
    </head>
    <body>
        <div id="test">滚动试试</div>
        <script>
            function toolbar(el){
                el = typeof el == 'string' ? document.getElementById(el) : el;
                var elTop = el.offsetTop;
                var sTop = 0;
                window.onscroll = function(){
                    sTop = document.body.scrollTop || document.documentElement.scrollTop;
                    if( sTop > elTop ){
                        el.style.top = sTop + 'px';
                    }else{
                        el.style.top = elTop + 'px';
                    }
                }
            }
            toolbar('test');
        </script>
    </body>
</html>

------解决方案--------------------
探讨

HTML code

<!DOCTYPE HTML>
<html>
<head>
<meta charset="gb2312" />
<title></title>
<style>
body {
height:2000px;
}
div……