简体   繁体   English

如何使用HTML和CSS使菜单在单击时向右滑动?

[英]How to make menu to slide right on click using HTML and CSS?

I have an HTML page in which there is an side menu bar that displays a list of dashboards which is done using Django. 我有一个HTML页面,其中有一个侧边菜单栏,显示使用Django完成的仪表板列表。 i want this menu(left-side menu) to show only a part of it when logged in and show fully after clicking on it. 我希望此菜单(左侧菜单)在登录时仅显示其中一部分,并在单击后完全显示。

The code for the html looks like this: html的代码如下所示:

 <div class="row"> <div class="col-sm-3 col-md-2 sidebar"> <ul class="nav nav-sidebar"> <li><span style="color:blue; font-weight:bold;">Dashboards</span></li> {% for Dashboard in dashboards %} <li><a href="{{ Dashboard.d_url }}" target="iframe_a">{{ Dashboard.d_name }}</a></li> {% endfor %} </ul> </div> 

since i am not familiar with jquery and all i want to know if there are any ways which works with only css and javascript to do this. 因为我不熟悉jquery,所以我想知道是否有任何方法仅可使用css和javascript来做到这一点。 when i open my html file it looks like this 当我打开html文件时,它看起来像这样 在此处输入图片说明 after clicking on icon 点击图标后 在此处输入图片说明

Is not very clear what you are trying to do, but i understand that is something like transition: left 1s; 尚不清楚您要做什么,但我知道这就像transition: left 1s; or transition: transform 1s ; transition: transform 1s and when you press your button toggles a class for changing left or transform: translateX(value); 当您按下按钮时,将切换一个用于lefttransform: translateX(value);的类transform: translateX(value); styles like this example 这样的样式

But also you need to understand if that menu will push your other content or not. 但是,您还需要了解该菜单是否可以推送您的其他内容。

That's a basic transition and a basic Layout i'm not sure if it fits on your requirements. 这是一个基本的过渡和一个基本的布局,我不确定它是否适合您的要求。 Also for IE9 and older browsers support you might want to check animations using jQuery or jQuery UI 另外,对于IE9和更早版本的浏览器支持,您可能希望使用jQuery或jQuery UI检查动画

check out this code of javascript which does required 查看此javascript代码,它确实需要

 $("#menu-button").bind( "click", function() { $('#mobile-menu').toggleClass('open'); $('#overlay').show(0); }); $("#overlay").bind( "click", function() { $('#mobile-menu').removeClass('open'); $('#overlay').hide(0); //basically so that clicking outside closes the menu; but on mobile I think it's immediately undoing the add class above }); $('#menu-button').click(function(){ $(this).find('span').toggleClass('glyphicon-chevron-right glyphicon-chevron-left') }); 

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

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