通过该实例的学习让自己对之前学过的只是有了更深的理解,真的是要多练习,这样才能写的快,怎么感觉老师讲的时候十几分钟连讲带些都可以,自己写着没什么感觉,1个小时就过去了。差别不是一般的大,通过该实例的练习让自己对 fade淡入淡出和slide 滑入滑出有了更深的记忆,实例如下:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>三级下拉菜单</title> <link rel="shortcut icon" type="image/x-icon" href="../picture/mi.png"> <link rel="stylesheet" type="text/css" href="../css/css.css"> <script type="text/javascript" src="jquery-3.3.1.min.js"></script> <style type="text/css"> .menu{width: 510px;height: 40px;background: #000;margin: 0pc auto;border: 1px solid #ccc;border-radius: 5px;margin-top: 15px;} ul li{width: 100px;height:40px;text-align: center;float: left;border-right: 1px solid #ccc;line-height: 40px;color: #ccc;cursor: pointer;} ul{list-style: none;} .twoMenu li{width: 100px;height: 30px;line-height: 30px;background: #2D2D2D;color: #A9A9A9; font-size: 14px;position: relative;border:0px;} .threeMenu {position: absolute; top: 0px;left: 100px;} .twoMenu li:hover{background: #000;} </style> </head> <body> <!-- 主导航条框架 --> <div> <!-- 主导航内容 --> <ul> <li>首页</li> <li>视频 <ul> <li>综艺</li> <li>喜剧 <!-- 三级导航 --> <ul> <li>喜剧1</li> <li>喜剧2</li> <li>喜剧3</li> </ul> </li> <li>古装</li> </ul> </li> <li>新闻</li> <li>小说 <ul> <li>小说1</li> <li>小说2 <ul> <li>001</li> <li>002</li> <li>003</li> <li>004</li> </ul> </li> <li>小说3</li> <li>小说4</li> </ul> </li> <li>综艺</li> </ul> </div> <script type="text/javascript"> $(document).ready(function(){ $('.twoMenu').hide(); $('.threeMenu').hide(); $('.oneMenu>li').mousemove(function(){ // 二级导航向下滑出 $(this).find('.twoMenu').fadeIn(500); }) $('.oneMenu>li').mouseleave(function(){ // 二级导航向上滑入 $(this).find('.twoMenu').fadeOut(500); }) $('.three').mousemove(function(){ // 三级导航向下滑出即鼠标一移动到.three上时自动滑出 $('.three').find('.threeMenu').fadeIn(500); }) $('.three').mouseleave(function(){ // 三级导航上滑入即鼠标移开后自动隐藏三级菜单 $('.three').find('.threeMenu').fadeOut(500); }) }) </script> </body> </html>