Twitter Bootstrap - how to detect when media queries starts

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

    here is my solution for bootstrap 4, based on @falsarella idea

    *note: use "full page" option below for test this snippet, otherwise it will return wrong screen type, based on snippet iframe size

    /**
     * @returns STRING current screen type like: xs, sm, md, lg or xl
     */
    function getScreenType() {
    
      !function initHelpers() {
        if ($('div.mq-detector').length !== 0) return;
        $('body').append(_mqDetector());
        // helpers
        function _mqDetector() {
          return `
          
          `;
        }
      }();
    
      // @then
    
      return $('div.mq-detector').children().filter(':visible').data('type');
    
    }
    
    console.log(getScreenType())
    
    
    

提交回复
热议问题