0
在下面的代码中,当menuLeft
具有类'cbp-spmenu-open'时,它会显示在屏幕上。当它没有这个类时,它不在屏幕上。努力获得一些基本的JQuery和JS代码
我试图做一些代码,以便当菜单在屏幕上时,当用户点击除菜单之外的任何东西时,它将消失。
在下面我的代码,林基本上是试图告诉它:
如果菜单屏幕上,点击任何东西,但网页制作菜单消失。
不太确定我出错的地方,所以如果有人可以发布一些很棒的正确代码!谢谢。
if ($('.menuLeft').hasClass('cbp-spmenu-open')) {
$("*").not("#menuRight").click(function() {
classie.toggle(menuLeft, 'cbp-spmenu-open');
});
}
编辑:
var menuLeft = document.getElementById('cbp-spmenu-s1'),
menuRight = document.getElementById('cbp-spmenu-s2'),
menuTop = document.getElementById('cbp-spmenu-s3'),
menuBottom = document.getElementById('cbp-spmenu-s4'),
// showLeft = document.getElementById('showLeft'),
showRight = document.getElementById('showRight'),
showTop = document.getElementById('showTop'),
showBottom = document.getElementById('showBottom'),
showLeftPush = document.getElementById('showLeftPush'),
showRightPush = document.getElementById('showRightPush'),
body = document.body;
var showLeft=document.getElementsByClassName('showLeft');
for(var i=0;i<showLeft.length;i++) {
showLeft[i].onclick = function() {
classie.toggle(this, 'active');
classie.toggle(menuLeft, 'cbp-spmenu-open');
disableOther('showLeft');
};
}
// showLeft.onclick = function() {
// classie.toggle(this, 'active');
// classie.toggle(menuLeft, 'cbp-spmenu-open');
// disableOther('showLeft');
// };
showRight.onclick = function() {
classie.toggle(this, 'active');
classie.toggle(menuRight, 'cbp-spmenu-open');
disableOther('showRight');
};
showTop.onclick = function() {
classie.toggle(this, 'active');
classie.toggle(menuTop, 'cbp-spmenu-open');
disableOther('showTop');
};
showBottom.onclick = function() {
classie.toggle(this, 'active');
classie.toggle(menuBottom, 'cbp-spmenu-open');
disableOther('showBottom');
};
showLeftPush.onclick = function() {
classie.toggle(this, 'active');
classie.toggle(body, 'cbp-spmenu-push-toright');
classie.toggle(menuLeft, 'cbp-spmenu-open');
disableOther('showLeftPush');
};
showRightPush.onclick = function() {
classie.toggle(this, 'active');
classie.toggle(body, 'cbp-spmenu-push-toleft');
classie.toggle(menuRight, 'cbp-spmenu-open');
disableOther('showRightPush');
};
function disableOther(button) {
if(button !== 'showLeft') {
classie.toggle(showLeft, 'disabled');
}
if(button !== 'showRight') {
classie.toggle(showRight, 'disabled');
}
if(button !== 'showTop') {
classie.toggle(showTop, 'disabled');
}
if(button !== 'showBottom') {
classie.toggle(showBottom, 'disabled');
}
if(button !== 'showLeftPush') {
classie.toggle(showLeftPush, 'disabled');
}
if(button !== 'showRightPush') {
classie.toggle(showRightPush, 'disabled');
}
}
你的代码的结果是什么? – joozek 2015-02-09 20:23:54
什么是'classie'? – dave 2015-02-09 20:27:09
如果您的意思是在控制台中,它会显示'ReferenceError:Can not find variable:showLeft'。代码本身对页面没有任何影响。 – George 2015-02-09 20:28:17