js实现下拉菜单动画效果
2017-01-08 16:53
447 查看
js实现下拉菜单动画效果
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>$Title$</title> <style type="text/css"> .top-nav { font-size: 14px; font-weight: bold; list-style: none; } .top-nav li { float: left; margin-right: 1px; } .top-nav li a { line-height: 34px; text-decoration: none; background: #3f240e; color: #fff; display: block; width: 80px; text-align: center; } .top-nav ul { list-style: none; display: none; padding: 0; position: absolute; height: 0; overflow: hidden; } .top-nav li a:hover { background: url(http://img.imooc.com/5461b50d0001e28000010034.jpg) 0 0 repeat-x; } .note { color: #3f240e; display: block; background: url(http://img.imooc.com/5461b50d0001e28000010034.jpg) 0 0 repeat-x; } .corner { display: block; height: 11px; background: url(http://img.imooc.com/5461b5620001410d00170011.jpg) 31px 0 no-repeat; } </style> <!--js实现--> <script type="text/javascript"> var t_over,t_leave; window.onload = function () { var Lis = document.getElementsByTagName("li"); //鼠标经过时的效果 for(var i=0;i<Lis.length;i++){ Lis[i].onmouseover = function () { var u = this.getElementsByTagName("ul")[0]; if (u != undefined) { u.style.display="block"; clearTimeout(t_leave); ChangeH(u.id,1); } }; Lis[i].onmouseleave = function () { var u = this.getElementsByTagName("ul")[0]; if (u != undefined) { clearTimeout(t_over); 4000 ChangeH(u.id,-1); } }; } }; function ChangeH(id, count) { // 根据ID找到ulList,同时得到其高度 var ulList = document.getElementById(id); var h = ulList.offsetHeight; h += count; if (count > 0) { if (h <= 42) { // 将高度赋值给ulList,同时,不断调用本函数 ulList.style.height = h + "px"; t_over = setTimeout("ChangeH('" + id + "',1)", 10); } else { return; } } else { if (h > 0) { // 将高度赋值给ulList,同时,不断调用本函数 ulList.style.height = h + "px"; t_leave = setTimeout("ChangeH('" + id + "',-1)", 10); } else { ulList.style.display = "none"; return; } } } </script> <!--jQuery实现,有问题,只看思路--> <!--<script src="http://libs.baidu.com/jquery/1.11.1/jquery.min.js"></script>--> <!--<script type="text/javascript">--> <!--$(document).ready(function(){--> <!--$(".top-nav li").mousemove(function(){--> <!--$(this).find("ul").slideDown("1000");--> <!--});--> <!--$(".top-nav li").mouseleave(function(){--> <!--$(this).find("ul").slideUp("slow");--> <!--});--> <!--})--> <!--</script>--> </head> <body> <ul class="top-nav"> <li><a href="#"><span class="note">Mijiang</span></a> </li> <li><a href="#">课程大厅</a> </li> <li><a href="#">学习中心</a> <ul id="mnuUL"> <span class="corner"></span> <li><a href="#">前端课程 </a></li> <li><a href="#">手机开发</a> </li> <li><a href="#">后台编程</a></li> </ul> </li> <li><a href="#">关于我们</a></li> </ul> </body> </html>
相关文章推荐
- 图片的左右移动,js动画效果实现代码
- 用js实现的动画效果
- js实现横向百叶窗效果网页切换动画效果的方法
- JS动画效果打开、关闭层的实现方法
- JS 实现回到页面TOP的动画效果
- 20150730 JS动画效果实现
- js实现绿白相间竖向网页百叶窗动画切换效果
- JS实现超炫网页烟花动画效果的方法
- JS简单实现动画弹出层效果
- 在iframe里的页面编写js,实现在父窗口上创建动画效果展开和收缩的div(不变动iframe父窗口代码)
- js实现div整块向上移动的动画效果
- js实现菜单栏上下旋转动画效果
- JS简单实现动画弹出层效果
- JS+CSS实现Google首页的动画效果
- 用js实现类似jquery里的animate动画效果
- 实现动画效果核心方式的js代码
- 纯CSS3实现带动画效果导航菜单无需js
- JS动画效果打开、关闭层的实现方法
- 利用JS和css3实现动画效果替代js的时间事件
- js实现横向百叶窗效果网页切换动画效果的方法