0

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. 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/

PEHLAJ
  • 9,980
  • 9
  • 41
  • 53
mittal3795
  • 35
  • 1
  • 1
  • 12

2 Answers2

1

Check the fiddle at https://jsfiddle.net/Lfa6vef6/2/ - this seems to be what you want to do. 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.

Dhananjay
  • 544
  • 3
  • 7
1

You can try the bellow script. I test it at the jsfiddle link you share. I just change the sidebar with sidebar_test. Because sidebar consider the left bar of the 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";
});
sina_Islam
  • 1,068
  • 12
  • 19