最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Bootstrap Tooltip hides selectortoggle element - Stack Overflow

programmeradmin0浏览0评论

I'm using Bootstrap 2.3.2. My tooltips show up as expected, but when hovering off of the triggering element, the tooltip AND the triggering element are both hidden. There is an inline style of display:none being applied to the triggering element.

What is the best way to diagnose why this is happening? I fear it may be another JS library conflicting, but I'm not sure how to capture the event that is adding display:none to the triggering element.

I'm using Bootstrap 2.3.2. My tooltips show up as expected, but when hovering off of the triggering element, the tooltip AND the triggering element are both hidden. There is an inline style of display:none being applied to the triggering element.

What is the best way to diagnose why this is happening? I fear it may be another JS library conflicting, but I'm not sure how to capture the event that is adding display:none to the triggering element.

Share Improve this question edited Jun 26, 2013 at 17:15 madth3 7,34412 gold badges52 silver badges74 bronze badges asked Jun 26, 2013 at 1:51 professormeowingtonsprofessormeowingtons 3,5147 gold badges38 silver badges52 bronze badges 1
  • Could you provide a link to the site you're having the issue on? – foiseworth Commented Jun 26, 2013 at 8:43
Add a comment  | 

5 Answers 5

Reset to default 9

I actually discovered this is a namespacing conflict from interaction between Prototype and Bootstrap 2.3.

https://github.com/twitter/bootstrap/issues/6921

Best bet is to comment out line this.$element.trigger(e) in bootstrap.js for now, or use 3.0 WIP.

Solution without any change on bootstrap.js

<span data-toggle="tooltip" data-placement="right" title="Tooltip on right">info</span>

jQuery

jQuery(document).ready(function(){
    jQuery('[data-toggle="tooltip"]').tooltip();          
    jQuery('[data-toggle="tooltip"]').on("hidden.bs.tooltip", 
         function() { 
          jQuery(this).css("display", "");
    });
});

Reference

Add this after jquery.js including

    jQuery.noConflict();

    //Remove conflict between prototype and bootstrap functions 
    if (Prototype.BrowserFeatures.ElementExtensions) {
        var disablePrototypeJS = function (method, pluginsToDisable) {
            var handler = function (event) {
                event.target[method] = undefined;
                setTimeout(function () {
                    delete event.target[method];
                }, 0);
            };
            pluginsToDisable.each(function (plugin) { 
                jQuery(window).on(method + '.bs.' + plugin, handler);
            });
        },
        pluginsToDisable = ['collapse', 'dropdown', 'modal', 'tooltip', 'popover', 'tab'];
        disablePrototypeJS('show', pluginsToDisable);
        disablePrototypeJS('hide', pluginsToDisable);
    }

This solution does not flicker...

$('[data-toggle="tooltip"]').tooltip()
.on('hide.bs.tooltip', function(e) {
    e.preventDefault();
    $('div.tooltip').hide();
});

For the googlers; for me all of the answers did not work. So here is (not the best) but a really simple workaround:

Add this to your css:

[data-toggle="tooltip"] {
  display: initial !important;
}
发布评论

评论列表(0)

  1. 暂无评论