当用户使用ipad时,如何更改a:link上的类?
我正在使用一个滑出灯盒来显示一个视频,但我希望当用户使用ipad时,灯箱会发生变化。
<a href="#" class="video">Watch</a>例如网络版本
/* Video overlay */
// Hide on load
$('.video-player').hide();
// Show the video player
$('.video').click(function() {
$('.video-player').show('slow');
return false;
});
//Hide the video player
$('.close-video').click(function() {
$('.video-player').hide('slow');
return false;
})IPAD版
/* Video overlay */
// Hide on load
$('.video-player').hide();
// Show the video player
$('.video').fancybox({
'content' : $('.video-player').html(),
'titlePosition' : 'inside',
'transitionIn' : 'none',
'transitionOut' : 'none',
'overlayColor' : '#fff',
'overlayOpacity' : 0,
'scrolling' : 'no',
'onComplete' : function(){
$('.pop-detail input.button, .pop-detail a').click(function(){
$.fancybox.close();
})
},
'onClosed' :function(){
}
});
//Hide the video player
$('.close-video').click(function() {
$('.video-player').hide();
return false;
})谢谢你的帮助。
发布于 2011-04-04 10:08:19
这将设置一个名为iPad的变量,该变量在iPad上为真,在其他地方为False。
var iPad = navigator.userAgent.match(/iPad/i) != null;您可以使用它来决定使用哪个代码路径来运行。
if (iPad) {
// iPad version
} else {
// Normal version
}发布于 2011-04-04 10:10:02
if (navigator.platform.indexOf("iPad") != -1)){
/* second code snippet, you are on the iPad */
}else{
/* first snippet, normal behaviour */
}发布于 2011-04-04 10:10:28
简短的回答:你不应该。在任何浏览器中使用相同体验的用户是一个主要的设计原则(如果没有分辨率限制,比如在手机中)
如果您还想这样做,请使用以下方法检测它:
jQuery(document).ready(function($){
var deviceAgent = navigator.userAgent.toLowerCase();
var agentID = deviceAgent.match(/(ipad)/);
if (agentID) {
// do something special
}
});参考资料:http://snipplr.com/view/31607/iphone-ipad-ipod-detect/
https://stackoverflow.com/questions/5537008
复制相似问题