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

后端 未结 7 882
小蘑菇
小蘑菇 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:22

    Building on @Raphael_ and @user568109 's answers, in Bootstrap 3, Responsive is now built in.

    To detect device type in Javascript, create an object that is only displayed on your required device using Bootstrap's Responsive classes. Then check its :hidden property.

    Example:

    1. Create a

      panel with no content that would be shown on anything bigger that an eXtra Small device (thanks to @Mario Awad) :

      
      

      or, to exclude specific devices:

    2. Check value of #desktopTest:

      if ($('#desktopTest').is(':hidden')) {
          // device is == eXtra Small
      } else {
          // device is >= SMaller 
      }
      

提交回复
热议问题