Twitter Bootstrap Tooltips on Hover & Focus

China☆狼群 提交于 2019-12-10 04:05:02

问题


Twitter bootstrap tooltip trigger default is hover.

I can add data-trigger="focus" to cause the tooltip to display on focus, but how I do both hover and focus?


回答1:


solution by @Adrian does not work on Bootstrap 3. Use following:

$('[rel=tooltip]').tooltip();
$(document).on('hover', '[rel=tooltip]', function () { $(this).tooltip('show'); });
$(document).on('focus', '[rel=tooltip]', function () { $(this).tooltip('show'); });



回答2:


have you tried data-trigger="focus hover"




回答3:


you can simply pass the trigger parameter :

$('[data-toggle="tooltip"]').tooltip({ trigger:'hover focus' });

see bootstrap tooltip article




回答4:


trigger is a single-value property, so you have to fake either of both methods:

$('.tooltip').tooltip({trigger: 'hover'}).each(function () {
  var $this = $(this), data = $this.data('tooltip');
  $this.on('focus.tooltip', $.proxy(data.enter, data))
    .on('blur.tooltip', $.proxy(data.leave, data));
});

Update: Alternatively, you can use my patch to Twitter Bootstrap to make trigger a multi-value property and just set it to hover focus.



来源:https://stackoverflow.com/questions/13572737/twitter-bootstrap-tooltips-on-hover-focus

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!