2014-02-05 25 views
1

我有JSjQuery的接近外DIV不工作在iOS上,但在Android

這一點點

變量$提示= $( 'tooltip__link。');

// tooltip/overlay toggle 
$tooltips.on('click', function(){ 
    var tooltip = $(this); 
    tooltip.toggleClass('js-opened'); 
    return false; 
}); 

// remove tooltip if clicked anywhere else 
// only works on 'desktop' 
$('body').on('click', function() { 
    $tooltips.removeClass('js-opened'); 
}); 

這的確消除了階級「JS開」在桌面瀏覽器,事實上在Android 4+元素之外點擊的時候,卻完全無法在iOS工作(7)和Android 2.3

任何人知道爲什麼這個代碼會這樣做?

回答

2

您需要使用touchstart

$tooltips.on('click touchstart', function(){ 
    var tooltip = $(this); 
    tooltip.toggleClass('js-opened'); 
    return false; 
}); 

$('body').on('click touchstart', function(){ 
    $tooltips.removeClass('js-opened'); 
}); 

如果這不起作用嘗試添加cursor: pointer到元素。這對iOS來說是一種解決方法。

+0

我試過這個,但jQuery的第二個片段(身體一)劫持頁面上的任何其他內容。有關於此的任何想法? –

+0

@StuartRobson你的意思是劫持其他任何東西?設置一個http://jsfiddle.net/,我可以給你更多的幫助。 – enyce12

相關問題