从单个按钮多次切换 Class?
Multiple Toggle Class's from single button?
我使用 classie 库
进行了以下工作
var body = document.body,
menuLeft = document.getElementById( 'cbp-spmenu-s1' ),
textPanel = document.getElementById( 'panel' ),
showLeftPush = document.getElementById( 'showLeftPush' ),
showLeftButton = document.getElementById( 'showLeftButton' );
showLeftPush.onclick = function() {
classie.toggle( this, 'active' );
classie.toggle( body, 'cbp-spmenu-push-toright' );
classie.toggle( menuLeft, 'cbp-spmenu-open' );
classie.toggle( textPanel, 'hide' );
};
当您单击带有 showLeftPush ID 的按钮时,所有其他按钮都会添加给定的 类。
我只是想知道是否有一种更简单的方法可以单独使用 jQuery 并且没有臃肿的经典位和鲍勃(反正不会很快得到支持)。
我不是 jQuery 大师,因此我首先使用 classie 库的原因:(
非常感谢。
试试下面的代码
$('#showLeftButton').click(function() {
$(this).toggleClass('active');
$("#panel").toggleClass('hide');
$('body').toggleClass('cbp-spmenu-push-toright');
$("#cbp-spmenu-s1").toggleClass('cbp-spmenu-open');
});
我使用 classie 库
进行了以下工作var body = document.body,
menuLeft = document.getElementById( 'cbp-spmenu-s1' ),
textPanel = document.getElementById( 'panel' ),
showLeftPush = document.getElementById( 'showLeftPush' ),
showLeftButton = document.getElementById( 'showLeftButton' );
showLeftPush.onclick = function() {
classie.toggle( this, 'active' );
classie.toggle( body, 'cbp-spmenu-push-toright' );
classie.toggle( menuLeft, 'cbp-spmenu-open' );
classie.toggle( textPanel, 'hide' );
};
当您单击带有 showLeftPush ID 的按钮时,所有其他按钮都会添加给定的 类。
我只是想知道是否有一种更简单的方法可以单独使用 jQuery 并且没有臃肿的经典位和鲍勃(反正不会很快得到支持)。
我不是 jQuery 大师,因此我首先使用 classie 库的原因:(
非常感谢。
试试下面的代码
$('#showLeftButton').click(function() {
$(this).toggleClass('active');
$("#panel").toggleClass('hide');
$('body').toggleClass('cbp-spmenu-push-toright');
$("#cbp-spmenu-s1").toggleClass('cbp-spmenu-open');
});