導航:首頁 > 編程語言 > 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實現導航欄下拉菜單相關的資料

熱點內容
壓縮完了文件去哪裡找 瀏覽:380
武裝突襲3浩方聯機版本 瀏覽:674
網路機頂盒移動網路 瀏覽:391
iphone手機百度雲怎麼保存到qq 瀏覽:148
資料庫設計與實踐讀後感 瀏覽:112
js對象是什麼 瀏覽:744
網頁文件存pdf 瀏覽:567
文件夾正裝 瀏覽:279
剛復制的文件找不到怎麼辦 瀏覽:724
試運行適用於哪些體系文件 瀏覽:987
ghost文件復制很慢 瀏覽:967
傑德原車導航升級 瀏覽:240
編程dest是什麼意思 瀏覽:935
linux埠鏡像 瀏覽:820
iphone5屏幕清塵 瀏覽:157
機頂盒密碼怎麼改 瀏覽:672
w7系統下載32位教程 瀏覽:618
pcb文件包括哪些內容 瀏覽:598
g00文件 瀏覽:607
用bat程序刪除程序 瀏覽:516

友情鏈接