导航:首页 > 编程语言 > js实现导航栏下拉菜单

js实现导航栏下拉菜单

发布时间:2023-02-14 10:23:11

㈠ 利用js实现新浪下拉菜单

<style>

        .clearfix::after {

            display: block;

            content: "";

            clear: both;

        }

        ul,

        li {

            list-style: none;

        }

        .nav>li {

            float: left;

            margin: 0 10px;

        }

        .nav>li ul {

            display: none;

        }

    </style>

</head>

<body>

    <ul class="nav clearfix">

        <li>

            <a href="">微博</a>

            <ul>

                <li>私信</li>

                <li>评论</li>

                <li>@我</li>

            </ul>

        </li>

        <li>

            <a href="">微博</a>

            <ul>

                <li>私信</li>

                <li>评论</li>

                <li>@我</li>

            </ul>

        </li>

        <li>

            <a href="">微博</a>

            <ul>

                <li>私信</li>

                <li>评论</li>

                <li>@我</li>

            </ul>

        </li>

        <li>

            <a href="">微博</a>

            <ul>

                <li>私信</li>

                <li>评论</li>

                <li>@我</li>

            </ul>

        </li>

    </ul>

    <script>

        //案例分析:导航栏里面的li都要有鼠标经过效果 所以需要循环注册鼠标事件

        //核心原理:当鼠标经过li里面的第二个孩子ul显示 当鼠标离开 ul隐藏

        var nav = document.querySelector('.nav');

        var lis = nav.children;

        for (var i = 0; i < lis.length; i++) {

            lis[i].onmouseover = function() {

                this.children[1].style.display = 'block';

            }

            lis[i].onmouseout = function() {

                this.children[1].style.display = 'none';

            }

        }

    </script>

㈡ 如何用js实现,点击按钮添加一个下拉菜单的功能

.DivHidden{ width:auto; height:auto; border:1px solid #ffffff; display:none;background-color:#cccccc;position:absolute; color:#ffffff; padding:5px;cursor:move;}
.DivHidden .conright_bottom table tr td{background-color:#4A535A; padding:5px; border-bottom:1px solid #333; border-right:1px solid #333;}
.DivHidden .conright_bottom{width:500px; height:auto}
上面是div样式
下面是div
<div class="DivHidden box">

</div>

㈢ 如何用原生js写出滑动下拉菜单

<!DOCTYPEhtml>
<htmllang="en">

<head>
<metacharset="UTF-8">
<title></title>
<style>
#menu{
position:relative;
background:black;
width:150px;
height:30px;
margin:200pxauto;
overflow:hidden;
}

#sc{
position:absolute;
background-color:#80ffff;
width:150px;
height:120px;
top:0;
}
</style>
<script>
</script>
</head>

<body>
<divid="menu">
<divid="sc"></div>
</div>
<script>
varmenu=document.getElementById('menu');
varsc=document.getElementById('sc');
varinterval;

functionmenuscroll(){
vartop=parseFloat(sc.style.top)||sc.scrollTop;
top+=10;
sc.style.top=top+"px";
}
menu.onmouseenter=function(){
interval=setInterval("menuscroll()",90);
}
menu.onmouseleave=function(){
clearInterval(interval);
sc.style.top=0;
}
</script>
</body>

</html>

㈣ js函数怎么写:下拉菜单下拉菜单0_0

下拉菜单关键在于HTML的布局和CSS的样式写法。这有这两个写好了后,js操作起来才非常的简单。下面是简单例子,仅供参考:
<htmlxmlns="http://www.w3.org/1999/xhtml"lang="zh-CN">
<head><metahttp-equiv="Content-Type"content="text/html;charset=gb2312"/>
<title>js菜单演示_怎么使用js_js下拉菜单_简单js下拉菜单_怎么做js下拉菜单</title>
<styletype="text/css">
*{margin:0;padding:0;border:0;}
body{font-family:arial,宋体,serif;font-size:12px;}
#nav{line-height:24px;list-style-type:none;background:#666;}
#nava{display:block;width:80px;text-align:center;}
#nava:link{color:#666;text-decoration:none;}
#nava:visited{color:#666;text-decoration:none;}
#nava:hover{color:#FFF;text-decoration:none;font-weight:bold;}
#navli{float:left;width:80px;background:#CCC;}
#navlia:hover{background:#999;}
#navliul{line-height:27px;list-style-type:none;text-align:left;left:-999em;width:180px;position:absolute;}
#navliulli{float:left;width:120px;background:#F6F6F6;}
#navliula{display:block;width:100px;text-align:left;padding-left:20px;}
#navliula:link{color:#666;text-decoration:none;}
#navliula:visited{color:#666;text-decoration:none;}
#navliula:hover{color:#F3F3F3;text-decoration:none;font-weight:normal;background:#C00;}
#navli:hoverul{left:auto;}
#navli.onhoverul{left:auto;}
#content{clear:left;}
</style>
<scripttype="text/javascript">
functionmenu(){
varoLi=document.getElementById("nav").getElementsByTagName("li");
for(vari=0;i<oLi.length;i++){
oLi[i].onmouseover=function(){
this.className+=(this.className.length>0?"":"")+"onhover";
};
oLi[i].onMouseDown=function(){
this.className+=(this.className.length>0?"":"")+"onhover";
}
oLi[i].onMouseUp=function(){
this.className+=(this.className.length>0?"":"")+"onhover";
};
oLi[i].onmouseout=function(){
this.className=this.className.replace(newRegExp("(?|^)onhover"),"");}}}
window.onload=menu;
</script></head>
<body>
<ulid="nav">
<li><ahref="http://jingyan..com/article/fc07f98917a56f12ffe5198a.html"target="_blank">动漫之家</a>
<ul>
<li>
<ahref="http://jingyan..com/article/363872ecedf4486e4ba16f92.html"target="_blank">下拉一</a></li>
<li><ahref="http://jingyan..com/article/363872ecedf4486e4ba16f92.html"target="_blank">下拉二</a></li>
<li><ahref="http://jingyan..com/article/363872ecedf4486e4ba16f92.html"target="_blank">下拉三</a></li>
<li><ahref="http://jingyan..com/article/363872ecedf4486e4ba16f92.html"target="_blank">下拉四</a></li>
</ul></li><li><ahref="http://jingyan..com/article/e73e26c0cfa01724adb6a795.html"target="_blank">js详解</a><ul>
<li><ahref="http://jingyan..com/article/e73e26c0cfa01724adb6a795.html"target="_blank">下拉一</a></li>
<li><ahref="http://jingyan..com/article/e73e26c0cfa01724adb6a795.html"target="_blank">下拉二</a></li>
<li><ahref="http://jingyan..com/article/e73e26c0cfa01724adb6a795.html"target="_blank">下拉三</a></li>
<li><ahref="http://jingyan..com/article/e73e26c0cfa01724adb6a795.html"target="_blank">下拉四</a></li></ul></li>
<li><ahref="http://jingyan..com/article/08b6a591f09cfc14a8092293.html"target="_blank">js运用</a>
<ul><li><ahref="http://jingyan..com/article/08b6a591f09cfc14a8092293.html"target="_blank">下拉一</a></li>
<li><ahref="http://jingyan..com/article/08b6a591f09cfc14a8092293.html"target="_blank">下拉二</a></li>
<li><ahref="http://jingyan..com/article/08b6a591f09cfc14a8092293.html"target="_blank">下拉三</a></li>
<li><ahref="http://jingyan..com/article/08b6a591f09cfc14a8092293.html"target="_blank">下拉四</a></li></ul></li>
<li><ahref="http://jingyan..com/article/363872ecedf4486e4ba16f92.html"target="_blank">关于我们</a>
<ul><li><ahref="http://jingyan..com/article/363872ecedf4486e4ba16f92.html"target="_blank">下拉一</a></li>
<li><ahref="http://jingyan..com/article/363872ecedf4486e4ba16f92.html"target="_blank">下拉二</a></li>
<li><ahref="http://jingyan..com/article/363872ecedf4486e4ba16f92.html"target="_blank">下拉三</a></li>
<li><ahref="http://jingyan..com/article/363872ecedf4486e4ba16f92.html"target="_blank">下拉四</a></li>
</ul></li><li><ahref="http://jingyan..com/article/cdddd41c5e873153cb00e193.html"target="_blank">js在线演示</a>
<ul><li><ahref="http://jingyan..com/article/cdddd41c5e873153cb00e193.html"target="_blank">下拉一</a></li>
<li><ahref="http://jingyan..com/article/cdddd41c5e873153cb00e193.html"target="_blank">下拉二</a></li>
<li><ahref="http://jingyan..com/article/cdddd41c5e873153cb00e193.html"target="_blank">下拉三</a></li>
<li><ahref="http://jingyan..com/article/cdddd41c5e873153cb00e193.html"target="_blank">下拉四</a></li></ul></li>
<li><ahref="http://jingyan..com/article/76a7e409bb3c33fc3b6e1593.html"target="_blank">联系我们</a>
<ul><li><ahref="http://jingyan..com/article/76a7e409bb3c33fc3b6e1593.html"target="_blank">下拉一</a></li>
<li><ahref="http://jingyan..com/article/76a7e409bb3c33fc3b6e1593.html"target="_blank">下拉二</a></li>
<li><ahref="http://jingyan..com/article/76a7e409bb3c33fc3b6e1593.html"target="_blank">下拉三</a></li>
<li><ahref="http://jingyan..com/article/76a7e409bb3c33fc3b6e1593.html"target="_blank">下拉四</a></li></li></ul>
</body>
</html>

㈤ 怎么用JS写个下拉菜单

其实思路很容易的,先做大导航。然后做下拉菜单,但是下拉菜单默认是display:专none;当鼠标指向上边属的大导航的项目的时候(mouseover),对应的下拉菜单的CSS样式中的display属性设置为block,mouseout的时候又置为none;

㈥ html+css+javascript 菜单单击式下拉菜单怎么弄

  1. 写好HTML代码以实现下拉菜单。

  2. CTR+S保存代码,在浏览器中F5刷新网页查看效果。

阅读全文

与js实现导航栏下拉菜单相关的资料

热点内容
w7系统下载32位教程 浏览:618
pcb文件包括哪些内容 浏览:598
g00文件 浏览:607
用bat程序删除程序 浏览:516
dnf鬼泣90版本打安图恩 浏览:668
245倒角编程怎么计算 浏览:599
可以买生活用品的app有哪些 浏览:175
cad在c盘产生的文件夹 浏览:541
联想手机解锁工具 浏览:696
瑞银3887win10 浏览:833
学网络编程哪个好 浏览:805
手机vmos导入的文件在哪里 浏览:115
苹果手机可以把文件传到华为吗 浏览:63
海川化工下载的文件默认到哪里 浏览:343
学唱粤语歌app 浏览:975
qq游戏生死狙击玩不了 浏览:120
win10邮件不显示图片 浏览:922
口袋妖怪所有版本下载 浏览:504
我们身边都有哪些大数据例子 浏览:25
震旦adc307扫描的文件在哪里 浏览:999

友情链接