简体   繁体   English

如何通过单击网站徽标打开和关闭左侧导航栏

[英]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. 跟踪侧栏是否在变量中展开,并使用其值调用openNavcloseNav来切换侧栏。

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.

相关问题 单击<a>链接</a>时如何关闭导航栏<a>?</a> - How do i get the navbar to close when i click on a <a> link? 如何通过点击关闭我的twitter bootstrap导航栏? - How do I get my twitter bootstrap navbar to close on click? 单击导航栏外部时如何关闭导航栏? - How to close navbar when I click outside the navbar? 如何关闭和打开导航栏 - How could to close and open navbar 如何创建一个可滑动的导航栏,以使网站的其余部分在打开时变暗? - How do I create a sliding side navbar that dims the rest of the website when open? 单击其中一个部分时如何关闭导航栏? - How to close my navbar when I click on one of the sections? 每当我单击js中的按钮时,如何关闭最后打开的window - How do I close the last open window whenever I click the button in js 在外部单击并链接时如何关闭导航栏 - How do i close Navbar when clicked outside and link 如何在浏览器的新窗口中打开指向网站的链接并阻止当前网站,直到用户完成或关闭新网站? - How do I open a link to a website on a new window in a browser and block the current website until the user finish or close the new one? 如果单击文件夹图标而不仅仅是三角形图标,我如何让 jstree 关闭/打开 - How do I get jstree to close/open if you click on folder icon not just the triangle icon
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM