How to detect which device view you're on using Twitter Bootstrap API?

后端 未结 7 909
小蘑菇
小蘑菇 2020-12-02 06:54

I have just started to play around with Twitter Bootstrap API for a project I have coming up. The main nav contains 3 main elements:

  • site nav
  • social l
7条回答
  •  被撕碎了的回忆
    2020-12-02 07:25

    Combining the answers from above, this one works for me:

    function findBootstrapDeviceSize() {
      var dsize = ['lg', 'md', 'sm', 'xs'];
      for (var i = dsize.length - 1; i >= 0; i--) {
    
        // Need to add   for Chrome. Works fine in Firefox/Safari/Opera without it.
        // Chrome seem to have an issue with empty div's
        $el = $('
     
    '); $el.appendTo($('body')); if ($el.is(':hidden')) { $el.remove(); return dsize[i]; } } return 'unknown'; }

提交回复
热议问题