简体   繁体   English

生成JavaScript以创建下拉菜单

[英]Generate JavaScript to make a dropdown menu

First, I tried to make a Dropdownmenu directly in the CSS but it doesn't work like that, because I use ASP.NET and the html Code gets generated. 首先,我尝试直接在CSS中创建一个Dropdownmenu,但它不能那样工作,因为我使用ASP.NET并生成了html代码。 Here's my jsfiddle for my html code: https://jsfiddle.net/rxLg0bo4/2/ 这是我的html代码的jsfiddle: https ://jsfiddle.net/rxLg0bo4/2/
And this is how my menu works in ASP: 这就是我的菜单在ASP中的工作方式:

<nav id="menu">

            <asp:Panel ID="pnlMenu" runat="server"></asp:Panel>
            <asp:Panel ID="pnlSubmenu" runat="server">
                <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
                </asp:ContentPlaceHolder>
            </asp:Panel>
        </nav>

But now I know that I have to use a JavaScript, because I can't adress some of them, if you look at the jsfiddle you will get it. 但是现在我知道我必须使用JavaScript,因为我不能解决其中的一些问题,如果您看一下jsfiddle,您将得到它。
But I don't really know JavaScript, so I need some help. 但是我不太了解JavaScript,因此需要一些帮助。 This is a script, which I made: 这是我编写的脚本:

  $('#pnlmenu').on('click', function click(){
        $('#pnlSubmenu').height(50);});

So in the end I would like to have it work like that: 因此,最后我想让它像这样工作:
When you hover over menu1, the first submenupanel should dropdown with its submenulinks. 当您将鼠标悬停在menu1上时,第一个子菜单应带有其子菜单。 Can anyone show me how to do that? 谁能告诉我该怎么做?

You can use mouseover and mouseout events of jquery to fadeIn/fadeOut the menu see this JSFiddle to get you started, but you need to work out the other way so your submenu needs visibility toggled instead. 您可以使用jquery的mouseovermouseout事件来fadeIn/fadeOut菜单,请参阅此JSFiddle入门,但是您需要采用其他方法进行处理,因此需要切换可见性的子菜单。

$( "#pnlMenu .menu_link" ).mouseover(function() {
    $(".submenu_panel").css("height", "100px");
    $("#pnlSubmenu").fadeIn( "slow" );
});

$( "#pnlMenu .menu_link" ).mouseout(function() {
    $(".submenu_panel").css("height", "0px");
    $("#pnlSubmenu").fadeOut( "slow" );
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM