문제

I am currently using the following code to initialize a lazy initialization version of Bootstrap tooltip. After the first hover everything works fine in regards to the delay, but on the initial hover it shows right away. I know this is because of the $(this).tooltip('show'); method, but I dont know how to use the delay and show at the same time. I have to use the $(this).tooltip('show'); because once hovered the element doesnt show the tooltip unless I move out and back in.

$(element).on('hover', '.item', function () {
    matchup = ko.dataFor(this).Matchup;

    if (matchup) {
        if ($(this).attr('data-original-title') != '') {
            $(this).tooltip({ title: matchup.Title, html: true, delay: 1000 });
            $(this).tooltip('show');
        }
    }
});

Updated Answer

  $(element).on('mouseenter', '.item', function (e) {

               matchup = ko.dataFor(this).Matchup;

                if (matchup) {

                    if ($(this).attr('data-original-title') != '') {

                            $(this)
                                .addClass('tooltip-init')
                                .tooltip({ title: matchup.Title, html: true, delay: { show: 1000, hide: 0 } })
                                .trigger(e.type);
                }
            });
도움이 되었습니까?

해결책

try use trigger

try the following code

$(this).tooltip({ 
    title: matchup.Title, 
    html: true, 
    trigger: 'hover',
    delay:  delay: { show: 2000, hide: 3000 }
}).trigger('hover');

다른 팁

I found Holmes answer using delay to work, but not reliably. When moving through a series of items, the hover seemed to stop showing. With the help of another stackoverflow answer leading to this jsfiddle by Sherbrow, I simplified the code and got it working in this jsfiddle. Simplified code below:

var enterTimeout = false;
$('[rel="tooltip"]').tooltip({trigger:'manual'}).on('mouseenter', function() {
    var show = function(n) {
        enterTimeout = setTimeout(function(n) {
            var isHovered = n.is(":hover"); 
            if (isHovered) n.tooltip('show');
            enterTimeout = false;
        }, 750);
    };
    if(enterTimeout) clearTimeout(enterTimeout);
    show( $(this) );
});

$('[rel="tooltip"]').on('mouseout click',function() {
    $(this).tooltip('hide');
});
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top