zoukankan      html  css  js  c++  java
  • 碰撞缓冲效果的导航条 js

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html>
    <head>
    <title>碰撞缓冲效果的导航条</title>
    <style type="text/css">
    * { padding: 0; margin: 0; }
    li { list-style: none; }
    body { background: #fff; }
    ul { 202px; margin: 40px auto 0; position: relative; }
    li { 200px; height: 30px; line-height: 30px; padding-left: 10px; border: 1px solid #ccc; border-left: 3px solid #666; font-size: 14px; color: #333; margin-bottom: 5px; position: relative; z-index: 2; }
    a { color: #333; text-decoration: none; }
    .active { font-weight: bold; background: #fff0f0; }
    #bar { 10px; padding-left: 0; background: #cc6699; border: 1px solid #cc6699; position: absolute; top: 0; left: -14px; z-index: 3; }
    </style>
    <script type="text/javascript">
        var obj = null;
        var aLis = null;
        var oBar = null;
        var iTime = null;
        var iSpeed = 0;
        var iAcc = 3;
        var onOff = 0;
        var iPrev = 0;
        var iNext = 0;
        function goTime() {
            for (var i = 0; i < aLis.length; i += 1) {
                if (aLis[i] === this) {
                    var iTarget = (aLis[0].offsetHeight + 5) * i;
                    iNext = i;
                    onOff = iNext - iPrev;
                    if (iTime) {
                        clearInterval(iTime);
                    }
                    if (onOff >= 0) {
                        iTime = setInterval("elasticity(" + iTarget + ")", 35);
                    }
                    else {
                        iTime = setInterval("postpone(" + iTarget + ")", 35);
                    }
                    iPrev = iNext;
                }
                aLis[i].className = "";
                this.className = "active";
            }
        }
        function elasticity(target) {
            var top = oBar.offsetTop;
            iSpeed += iAcc;
            top += iSpeed;
            if (top >= target) {
                iSpeed *= -0.7;
                if (Math.abs(iSpeed) <= iAcc) {
                    clearInterval(iTime);
                    iTime = null;
                }
                top = target;
            }
            oBar.style.top = top + "px";
        }
        function postpone(target) {
            if (oBar.offsetTop === target) {
                clearInterval(iTime);
                iTime = null;
            }
            else {
                iSpeed = (target - oBar.offsetTop) / 4;
                oBar.style.top = oBar.offsetTop + iSpeed + "px";
            }
        }
        window.onload = function () {
            obj = document.getElementById("nav");
            aLis = obj.getElementsByTagName("li");
            oBar = document.getElementById("bar");
            for (var i = 0; i < aLis.length; i += 1) {
                if (aLis[i].id != "bar") {
                    aLis[i].onmouseover = goTime;
                }
            }
        };
    </script>
    </head>
    <body>
    <ul id="nav">
    <li class="active"><a href="#">首页</a></li>
    <li><a href="/">烈火学院</a></li>
    <li><a href="/">妙味课程</a></li>
    <li><a href="/">联系方式</a></li>
    <li id="bar"></li>
    </ul>
    </body>
    </html>

    转载原文:http://www.veryhuo.com/a/view/31222.html

  • 相关阅读:
    jQuery的选择器中的通配符[id^='code']
    chorme插件 ,在浏览器上模拟手机,pad 查看网页|前端技术开发必备插件
    http://hsax.kcpci.com:81/admin/login.aspx
    ashx页面返回json字符串|jQuery 的ajax处理请求的纠结问题
    用NPOI创建Excel、合并单元格、设置单元格样式、边框的方法
    DataTable 导入到Excel的最佳选择Npoi
    隐藏和显示服务器端控件以及Html控件
    JS只能输入数字,数字和字母等的正则表达式
    把本地表导入远程表
    [flex & bison]编译器杂谈
  • 原文地址:https://www.cnblogs.com/lizihong/p/4012712.html
Copyright © 2011-2022 走看看