如何使用jquery区分1024px的桌面浏览器维度与平板电脑维度1024px

时间:2015-02-15 11:39:41

标签: javascript jquery html css

现在这可能听起来很尴尬,但我面临的问题是,我有桌面浏览器的基于滚动的动画功能,而其他 平板电脑浏览器的动画。现在我希望这些功能可以在尺寸为1024px的桌面上运行。后来,我发现iPad也有1024px的尺寸,现在我不想要在1024维度的桌面上运行的javascript动画功能,在iPad上运行,因为iPad的布局是完全不同的,动画是也不同。如何使用jquery在Desktop 1024px和iPad 1024 px之间创建区别?关于这个问题,你能给我什么建议?感谢您的回复。如果您需要模拟问题,请告诉我。抱歉英文不好。

2 个答案:

答案 0 :(得分:1)

正如上面提到的,最好使用功能检测而不是用户代理嗅探,所以最好在这里做,就是使用Modernizer.touch,因为他们说为什么重新发明轮子。所以让我们看看解决方案:

if(win.width >=1024 && Modernizr.touch == false) {
        /*This is for the desktop with a dimension of 1024px or above*/
        /*You can put any thing specific inside*/
}
  if(win.width == 1024 && Modernizr.touch == true) {
        /*This is for the tablet or touch interfaces with a dimension of 1024px*/
        /*You can put any thing specific inside*/
       /*there might be some mistake here but you get the idea !!*/
}

使用Modernizer JS非常容易和简单。我希望这回答了这个问题,当然是我的问题,我得到了我想要的东西,但是那里可能有更好的解决方案。

答案 1 :(得分:0)

var isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
if (isMobile)
{
  $('head').append('<link rel="stylesheet" href="css/StyleSheet-ipad.css">'); //Append ipad specific stylesheet
}