[英]How to run jQuery only on non-mobile browser?
I'm using this jQuery for an (excellent) lightbox-like plugin called zoombox : 我正在使用这个jQuery作为一个名为zoombox的(优秀的)类似灯箱的插件:
$('a.zoombox').zoombox({...});
It takes a
links in the form http://vimeo.com/15171582
, parses the vimeo id (15171582) and pops up a lightbox which loads an iframe
with this URL: 它需要http://vimeo.com/15171582
形式a
链接,解析vimeo id(15171582)并弹出一个灯箱,该灯箱使用以下URL加载iframe
:
http://player.vimeo.com/video/15171582?autoplay=1&title=0&byline=0&portrait=0&wmode=transparent
How can I modify the jQuery so that, when viewed on a mobile browser, 我如何修改jQuery,以便在移动浏览器上查看时
iframe
link? 简单链接转换为iframe
链接? You can use this: http://detectmobilebrowsers.com/ to detect mobile devices. 您可以使用: http : //detectmobilebrowsers.com/来检测移动设备。
Or detect window width like: 或检测窗口宽度如:
function isMobile() {
if(window.innerWidth <= 600) {
return true;
} else {
return false;
}
}
And make it responsive like: 并使其响应如下:
// keep original url
$('a.zoombox').each(function() {
var url = $(this).attr('href');
$(this).data('url',url);
});
// on load
doMagic();
// resizing
$(window).resize(function() {
doMagic();
});
// lightbox?
function doMagic() {
$('a.zoombox').each(function() {
var url = $(this).data('url');
$(this).attr('href',url);
});
if (!isMobile) {
$('a.zoombox').zoombox({...}); // lightbox here
}
}
// detect mobile
function isMobile() {
if(window.innerWidth <= 600) {
return true;
} else {
return false;
}
}
NOT TESTED 没有测试
edit: add doMagic call on load.. 编辑:加载时添加doMagic调用..
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.