문제

I've got this little bit of JS

var $tooltips = $('.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');
});

which indeed removes the class 'js-opened' on desktop browsers and indeed on Android 4+ when clicking outside the element, but fails completely to work on iOS(7) and Android 2.3

Anyone know why this code would do that?

도움이 되었습니까?

해결책

You need to use touchstart:

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

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

If this don't work try to add cursor: pointer to your elements. It's kind of a workaround for iOS.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top