Twitter Bootstrap - how to detect when media queries starts

后端 未结 16 771
抹茶落季
抹茶落季 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:52

    Excellent Tip, @falsarella!

    For those who like this sort of thing to not affect their actual markup the following works:

    $(function(){
    ...
    var mqClasses = ["visible-xs", "visible-sm", "visible-md", "visible-lg"];
    var mq = $("").appendTo($("body"));
    $.each(mqClasses, function(idx, val) {
        mq.append("");
    });
    function checkMQ() {
        var visible = mq.find(":visible").get(0).className;
        return visible.slice(-2);
    };
    
    function checkResize(){
        switch(checkMQ){
          case 'xs' : ...; break;
          case 'sm' : ...; break;
         ...
        }
    }
    $(window).on('resize', checkResize);
    checkResize(); //do it once when page loads.
    

提交回复
热议问题