纯粹的javascript切换meni闪烁

时间:2015-01-07 01:23:24

标签: javascript menu toggle

试图创建一个纯粹的javascript切换菜单,但它的闪烁,有什么建议吗?抱歉没有jquery请。     var getToggleId = document.querySelector(' button.menu_button');     var getMenubyId = document.getElementById(' menu');     var myWidth = document.documentElement.clientWidth;

function clickToggle(e){
var el = e.target;
if(el.className ==="menu_button"){
    if(getMenubyId.style.visibility == 'visible' && myWidth <= 600){
    getMenubyId.style.visibility = 'hidden';
    }else{
        getMenubyId.style.visibility = 'visible';
        }
 }
};

getToggleId.addEventListener('click', function(e){
clickToggle(e);
}, false);

function screenSize(){

if(window.innerWidth > 600 && getMenubyId.style.visibility == 'hidden'){
    getMenubyId.style.visibility = 'visible';
}else{
    getMenubyId.style.visibility = 'hidden';
}
};
window.addEventListener('resize', screenSize, false);

0 个答案:

没有答案