javascript - Is there a more efficient way of adding and removing these CSS classes with jQuery? -
i have below script uses slidebars show , hide side menu.
i need add , remove css class div tie things together. looking @ way adding , removing classes feel there's more efficient way?
function slidebarsstatus() { var windowwidth = $(window).width(); breakpoint = 992; if ( windowwidth > breakpoint ) { controller.open( 'site-menu' ); $('.site-wrap').addclass('menu-active'); } else { controller.close( 'site-menu' ); $('.site-wrap').removeclass('menu-active'); $('.site-wrap').addclass('menu-inactive'); } } slidebarsstatus(); $(window).on( 'resize', slidebarsstatus );
store jquery object variable:
var sitewrap = $('.site-wrap');
and chain methods variable:
sitewrap.removeclass('menu-active').addclass('menu-inactive');
or, if possible, media queries in css:
@media screen , (max-width: 991px) { .site-wrap { /* active appearance */ } } @media screen , (min-width: 992px) { .site-wrap { /* inactive appearance */ } }
Comments
Post a Comment