Using Modernizr to test for tablet and mobile - Opinions wanted

前端 未结 4 796
迷失自我
迷失自我 2020-12-02 18:37

I want to use Modernizr to detect whether a user is view a site on a desktop, tablet or mobile device.

My initial first thoughts are obviously to check screen sizes

4条回答
  •  南方客
    南方客 (楼主)
    2020-12-02 18:57

    You can use the following extension for Modernizr: https://www.npmjs.org/package/mobile-detect

    Or (without Modernizr) you could use Restive.JS to add a ".phone" or ".tablet"-class to your body: http://docs.restivejs.com

    (Look for "formfactor" down the page.)

提交回复
热议问题