简体   繁体   English

单击时显示菜单

[英]Show menu when clicked

i have the following menu: 我有以下菜单:

<div id ="navigation-menu">
    <div id ="squaremenu">
        <ul>
            <li><a class ="homemenu" href="#Home" data-menuanchor="#Home"><img id ="homemenu" src="homemenu.bmp" height="30" width="30" /><span id="spanhome">Home</span></a></li>
            <li><a class="imprimir" href="#Servicios" data-menuanchor="#Servicios"><img id ="imprimir" src="imprimir.bmp" height="30" width="30" /><span id="spanimprimir">Imprimir</span></a></li>
            <li><a class="contacto" href="#Contacto" data-menuanchor="#Contacto"><img id="contacto" src="contacto.bmp" height="30" width="30" /><span id="spancontacto">Contacto</span></a></li>
        </ul>
    </div>
</div>

styled with css. 用CSS样式。

http://jsfiddle.net/t86Vp/ http://jsfiddle.net/t86Vp/

I would like if it's possible to hide most of the menu to the left and unhide it everytime i click on the menu? 我想是否可以在每次单击菜单时将大多数菜单隐藏在左侧并取消隐藏? If it's possible anyone can give solution with javascript/css? 如果有可能有人可以使用javascript / css提供解决方案?

Thanks in advance. 提前致谢。

Thanks for your fast answer, i know i may not have explained myself well because english is not my main language. 感谢您的快速答复,我知道我可能无法很好地解释自己,因为英语不是我的主要语言。

Edit: What i really want is show only a portion of the menu, and everytime i clic it, then show or hide the other portion. 编辑:我真正想要的是仅显示菜单的一部分,每次我点击它时,然后显示或隐藏其他部分。

Once again, thanks for your fast answers 再次感谢您的快速答复

And sorry if i cant make myself clear english is not my main language. 对不起,如果我不能说清楚英语不是我的主要语言。

Solution for the people with the same problem/idea: (menu that open or close every time you click it 针对具有相同问题/想法的人的解决方案:(每次单击时都会打开或关闭的菜单

Thanks to @Sergio 感谢@Sergio

http://jsfiddle.net/6xCEp/2/ http://jsfiddle.net/6xCEp/2/

You could use this: 您可以使用此:

$('#squaremenu').on('click', function () {
    $(this).addClass('abrir');
});

CSS CSS

/************
*   ADDED
*/
#squaremenu img {
    display:none;
}

#squaremenu.abrir {
    width:36px !important;
}
#squaremenu.abrir img {
    display:block;
}
/***********
* END 
*/

#squaremenu {
    position:fixed;
    left:0px;
    top:150px;
    display:block;
    margin: 0px;
    border-top-right-radius: 8px;
    border-bottom-right-radius: 8px;
    background:rgba(43,50,61,1);
    font-size: 1em;
    color:white;
    width:10px; /* CHANGED!! */
    height:120px;
}

Demo 演示

You may need javascript for this. 您可能需要使用javascript。 Include jquery in your page and try this 在页面中包含jquery并尝试执行此操作

$("#squaremenu a").on("click", function(){
    var $this = $(this);    
    $this.find("span").toggleClass("menu-item-visible");
});

You may need to group all css styles that show that menu under one class, then toggle that class as shown above. 您可能需要将所有显示该菜单的css样式归为一类,然后如上所述切换该类。 In my example I used the class menu-item-visible 在我的示例中,我使用了menu-item-visible类

Let me know if you have any more questions on this or if it's not clear 如果您还有其他疑问或不清楚,请告诉我

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

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