Open and close side menu with same button

前端 未结 4 815
耶瑟儿~
耶瑟儿~ 2021-01-24 22:24

Currently I use one button to display a side menu and another to close it



        
4条回答
  •  礼貌的吻别
    2021-01-24 23:02

    You can use this simple approach using jQuery data attribute.

    Menu Button
    
    $('#menu').on('click', function(){
        if($(this).data('stat') == "close"){
            $(this).data('stat', 'open');
    
            /* open Menu code */
    
        }else if($(this).data('stat') == "open"){
            $(this).data('stat', 'close');
    
            /* close Menu code */
    
        }
    });
    

提交回复
热议问题