有人可以帮助我优化这个 Jquery 以从 DOM 中删除类列表吗?我的代码有效,但必须有一种方法可以做到这一点,而不必单独列出每个类。
jQuery(document).ready(function($){
if(window.innerWidth <= 960) {
$('.wow').removeClass("wow");
$('.animated').removeClass("animated");
$('.bounceInDown').removeClass( 'bounceInDown' );
$('.slideInLeft').removeClass( 'slideInLeft' );
$('.slideInRight').removeClass( 'slideInRight' );
$('.zoomInUp').removeClass( 'zoomInUp' );
}
});
最佳答案
您可以将所有类列到一个选择器中并一次删除所有类,例如 $('.animated,.bounceInDown,.slideInLeft,.slideInRight,.zoomInUp').removeClass('animated,bounceInDown, slideInLeft,slideInRight,zoomInUp');
,但这将删除每个选定元素的所有列出的类,这可能不是您想要完成的。
你可以使用 Array.prototype.forEach喜欢:
["animated", "bounceInDown", "slideInLeft", "slideInRight", "zoomInUp"].forEach(function (e) {
$('.' + e).removeClass(e);
});
关于javascript - 如何删除窗口宽度的类列表 - Jquery/Javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34818920/