admin管理员组文章数量:1328022
Is there any way I can restrict the execution (if statement) of javascript so that it only applies to desktop puters, It needs to be off when the user is on a mobile/tablet device. Below is the code, however obviously it applies for any device at the moment when the document is ready.
<script type="text/javascript">
$(document).ready(function(){
main_parallax();
main_scrolling();
sauces_slider();
});
</script>
Only the main_parallax();
function should be omitted when on a mobile/tablet device.
Is there any way I can restrict the execution (if statement) of javascript so that it only applies to desktop puters, It needs to be off when the user is on a mobile/tablet device. Below is the code, however obviously it applies for any device at the moment when the document is ready.
<script type="text/javascript">
$(document).ready(function(){
main_parallax();
main_scrolling();
sauces_slider();
});
</script>
Only the main_parallax();
function should be omitted when on a mobile/tablet device.
- 2 You Could Take a Look at the Useragent – Moritz Roessler Commented Dec 23, 2012 at 18:40
- stackoverflow./questions/4117555/… – adeneo Commented Dec 23, 2012 at 18:40
- Why does the effect need to be off on all mobile devices? Many tablets are strong enough to do all sorts of plex graphical things. Isn't this rather an issue of display resolution? – Pekka Commented Dec 23, 2012 at 18:49
- You might want to look at Modernizr, which makes it easy to test for "touch" events. There's no really solid way, no matter what library you use, to detect whether a device is a "mobile" device. – Pointy Commented Dec 23, 2012 at 18:49
- the parallax doesn't work properly on any device apart from desktop – Muhammed Bhikha Commented Dec 23, 2012 at 18:53
1 Answer
Reset to default 6One method is using the user agent, which you could do like this:
$(document).ready(function(){
if (/Android|BlackBerry|iPhone|iPad|iPod|webOS/i.test(navigator.userAgent) === false) {
main_parallax(); //Run main_parallax() not a mobile device
}
main_scrolling();
sauces_slider();
});
I would remend using feature detection instead, try looking into: Modernizr
本文标签: javascriptOnly execute JS function on desktop computers (parallax plugin)Stack Overflow
版权声明:本文标题:javascript - Only execute JS function on desktop computers (parallax plugin) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742245705a2439337.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论