仅在支持触摸事件时才使用Bootstrap工具提示?

时间:2013-08-08 12:52:34

标签: javascript twitter-bootstrap touch twitter-bootstrap-tooltip

我在我的网站上使用Bootstrap tooltips

$('body').tooltip({
  selector: '.help, .searchicons li, .user-prefs, .colour'
});

唯一的问题是,当它们连接到也附有特定触摸事件的元素时,它们在触摸设备上的工作效果不佳。

有没有办法可以在触摸元素上禁用它们?

1 个答案:

答案 0 :(得分:4)

您可以检测触控功能,然后仅在未启用触控时创建工具提示。

var is_touch_device = 'ontouchstart' in document.documentElement;

if (!is_touch_device) {
    $('body').tooltip({
        selector: '.help, .searchicons li, .user-prefs, .colour'
    });
}