2011-04-04 34 views
4

当用户使用ipad时,如何更改:link上的类。在使用IPAD和JQuery时更改类

我使用滑出的灯箱来显示视频,但我希望灯箱更改,当用户使用iPad。

<a href="#" class="video">Watch</a> 

e.g 网页版

/* 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; 
    }) 

感谢您的帮助。

回答

5

这将设置一个名为iPad的变量,在iPad上为True,在其他地方为False。

var iPad = navigator.userAgent.match(/iPad/i) != null; 

你可以用它来决定哪些代码路径使用

if (iPad) { 
    // iPad version 
} else { 
    // Normal version 
} 
0
if (navigator.platform.indexOf("iPad") != -1)){ 
    /* second code snippet, you are on the iPad */ 
}else{ 
    /* first snippet, normal behaviour */ 
} 
0

简短的回答运行:你不应该。 Provinding在他使用任何浏览器相同的体验,用户是主要的设计原则(如果有任何决议约束上,像手机)

如果您仍然想这样做,以检测它:

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/