教程集 www.jiaochengji.com
教程集 >  脚本编程  >  javascript  >  正文 Javascript富有弹性碰撞缓冲的竖向导航效果代码

Javascript富有弹性碰撞缓冲的竖向导航效果代码

发布时间:2016-10-14   编辑:jiaochengji.com
教程集为您提供Javascript富有弹性碰撞缓冲的竖向导航效果代码等资源,欢迎您收藏本站,我们将为您提供最新的Javascript富有弹性碰撞缓冲的竖向导航效果代码资源
这是一个不错的Javascript富有弹性碰撞缓冲的竖向导航效果代码,有需要的同学可进入参考参考。
提示:您可以先修改部分代码再运行

<textarea name="runcool" rows="28" cols="75" > <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>富有弹性碰撞缓冲的竖向导效果代码</title> <style type="text/css"> * { padding: 0; margin: 0; } li { list-style: none; } body { background: #fff; } ul { width: 202px; margin: 40px auto 0; position: relative; } li { width: 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 { width: 10px; padding-left: 0; background: #cc6699; border: 1px solid #cc6699; position: absolute; top: 0; left: -14px; z-index: 3; } </style> <script> 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">网站首页</li> <li>关于我们</li> <li>资源下载</li> <li>联系方式</li> <li id="bar"></li> </ul> </body> </html></textarea>
提示:您可以先修改部分代码再运行

您可能感兴趣的文章:
Javascript富有弹性碰撞缓冲的竖向导航效果代码
用缓冲技术提高JSP应用的性能和稳定性
使用javascript中canvas实现拼图小游戏
纯CSS制作的竖向导航菜单
《贪吃蛇》--H5小游戏开发
PHP基础之输出缓冲区基本概念、原理分析
javascript 仿FLASH效果的竖向导航菜单
使用canvas实现迷宫游戏
canvas实现弹球的代码示例
移动端HTML5中判断横屏竖屏的方法

[关闭]
~ ~