admin管理员组文章数量:1389855
I need to make sure that upon clicking a link to view a html file, on an iPhone or Android or any handheld, it doesn't use Fancybox to view it, as it does on a puter.
I've tried ways with @media with no luck.
Is there any code to disable certain bits of javascript depending on what device it is?
Thanks!
I need to make sure that upon clicking a link to view a html file, on an iPhone or Android or any handheld, it doesn't use Fancybox to view it, as it does on a puter.
I've tried ways with @media with no luck.
Is there any code to disable certain bits of javascript depending on what device it is?
Thanks!
Share Improve this question edited Jan 26, 2012 at 10:36 beryllium 29.8k15 gold badges109 silver badges127 bronze badges asked Jan 26, 2012 at 10:34 malicedixmalicedix 1292 gold badges5 silver badges14 bronze badges6 Answers
Reset to default 4Andre's solution will work for a specific subset of devices, but a better approach might be to do it based on screen size, since that's presumably why you don't want to use facnybox (because the screen is too small).
How about this:
if (window.innerWidth < 500 && window.innerHeight < 500) {
//small screen device - don't use fancy box
}
You can swap out the width and height for whatever the threshold is for fancybox looking okay.
I am using this approach and it is working fine for me...
if( $(window).width() > 480 && (!navigator.userAgent.match(/Android/i) ||
!navigator.userAgent.match(/webOS/i) ||
!navigator.userAgent.match(/iPhone/i) ||
!navigator.userAgent.match(/iPod/i) ||
navigator.userAgent.match(/BlackBerry/))
){
$(".royalSlide").click().fancybox({
'overlayShow' : false,
'transitionIn' : 'elastic',
'transitionOut' : 'elastic'
});
}
For fancybox 2 this worked for me.
$(".fancybox-img").click( function( e ) {
if ( window.innerWidth < 799 ) {
e.stopPropagation();
e.preventDefault();
}
})
$(".fancybox-img").fancybox( {
margin : 100,
autoSize : true,
});
<script src="https://ajax.googleapis./ajax/libs/jquery/2.1.1/jquery.min.js"></script>
you can use something like
if( navigator.userAgent.match(/Android/i) ||
navigator.userAgent.match(/webOS/i) ||
navigator.userAgent.match(/iPhone/i) ||
navigator.userAgent.match(/iPod/i) ||
navigator.userAgent.match(/BlackBerry/)
){
// your fancybox instantiation here
}
but it will never be 100% accurate
Thinking inside of the box, no pun intended, a non-js solution:
.fancybox-overlay {
display: none !important;
}
@media (min-width: 1200px) {
.fancybox-overlay {
display: block !important;
}
};
disable fancybox with screen size
@media (min-width: 1000px) {
.fancybox-is-open {
display: none !important;
}};
本文标签: javascriptDisable fancybox on handheldsStack Overflow
版权声明:本文标题:javascript - Disable fancybox on handhelds - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744602491a2615151.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论