Twitter Bootstrap - how to detect when media queries starts

后端 未结 16 760
抹茶落季
抹茶落季 2020-12-14 02:19

which is the fastest and easy way to fire when bootstrap-responsive.css media queries go in action?

go in action = when you resize window to mobile width and site is

16条回答
  •  时光取名叫无心
    2020-12-14 02:31

    This already answered on stackoverflow from Terryfrancis is still useful in my Bootstrap 4 application, when I wanted to change the class of a non-bootstrap module into .col-md in my Bootstrap 4 application.

    I used both onload and window resize function:

    // on load
    if ($(window).width() > 575 && $(window).width() < 992) {
       $('div').addClass('col-md-6').removeClass('col-md-4');
    } else if ($(window).width() > 992) {
        $('div').addClass('col-md-4').removeClass('col-md-6');
    }
    
    // on user resizes browser window
     $( window ).resize(function() {
    if ($(window).width() > 575 && $(window).width() < 992) {
       $('div').addClass('col-md-6').removeClass('col-md-4');
    } else if (jQuery(window).width() > 992) {
        $('div').addClass('col-md-4').removeClass('col-md-6');
    }
    });
    

提交回复
热议问题