[英]How Do i Open and Close Leftside navbar with click on Logo of website
I have an issue with my web pages in which I want to toggle the left side navigation bar open and close both by clicking on Logo of the web page. 我的网页出现问题,我想通过单击网页的徽标来切换左侧导航栏的打开和关闭两者。 but i am not able to do same, but unfortunately, i am able to open the navbar with click on Logo but not able to do same for close navbar by click on the logo (instead it close by click on outside area of navbar), so i have tried some of the code of my web page which is available in jsfiddle snippet in following.
但我无法做到这一点,但是不幸的是,我可以通过单击徽标来打开导航栏,但是不能通过单击徽标来关闭导航栏(而是通过单击导航栏的外部区域来关闭导航栏),所以我尝试了我的网页的一些代码,这些代码可以在下面的jsfiddle片段中找到。 it is good for me if anyone can able to solve this
如果有人能解决这个问题对我有好处
Note: Please Check Following Jsfiddle for understanding it better.
https://jsfiddle.net/v2a7xdmr/ https://jsfiddle.net/v2a7xdmr/
Check the fiddle at https://jsfiddle.net/Lfa6vef6/2/ - this seems to be what you want to do. 在https://jsfiddle.net/Lfa6vef6/2/上检查小提琴-这似乎是您想要做的。 Track if the sidebar is expanded or not in a variable and use its value to either invoke
openNav
or closeNav
to toggle the sidebar. 跟踪侧栏是否在变量中展开,并使用其值调用
openNav
或closeNav
来切换侧栏。
You can try the bellow script. 您可以尝试以下脚本。 I test it at the jsfiddle link you share.
我在您共享的jsfiddle链接上对其进行了测试。 I just change the sidebar with sidebar_test.
我只是用sidebar_test更改了侧边栏。 Because sidebar consider the left bar of the jsfiddle.
因为补充工具栏请考虑jsfiddle的左侧栏。
(window.openNav = function() {
var $device_width = $( window ).width();
if($device_width < 767 )
{
if(document.getElementById("sidebar").offsetWidth==0){
document.getElementById("sidebar").style.width = "250px";
}
else{
closeNav();
}
}else {
if(document.getElementById("sidebar").offsetWidth==0){
document.getElementById("sidebar").style.width = "350px";
}
else{
closeNav();
}
}
});
(window.closeNav = function() {
document.getElementById("sidebar").style.width = "0";
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.