如果检测到某个操作系统,是否有一种简单的方法可以排除某些代码?
我设计了一个效果很好的站点(这是一个侧滚器),当使用滚轮(上/下)时,它可以左右滚动.但是,如果您使用的是MacOS笔记本电脑,并且用两根手指向侧面滑动,它就会开始来回抖动.有没有办法排除侧滚动javascript的这一小片段?
解决方法:
您可以使用navigator.platform属性
<code>document.write("Platform: " + navigator.platform);
</code>
navigator.platform的返回类型为:“ Win32”,“ Linux i686”,“ MacPPC”,“ MacIntel”,“ Other”
因此,您可以执行以下操作:
<code>if(navigator.platform != "MacPPC" && navigator.platform != "MacIntel")
{
// put scrolling stuff here
// you actually don't need the MacPPC check
// b/c the laptops with swiping are all Intel based I believe
}
</code>
【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!