4

我想显示一个工具提示,它会在 3 秒后消失。

我应该如何修改我的代码?似乎注释代码不起作用:

http://jsfiddle.net/sMJ2T/1/

HTML

<div id="mytooltip" title="the message"></div>

JS

$(function() {
    $('#mytooltip').tooltip();

    $('#mytooltip').tooltip({
    open: function(e,o){
        $(o.tooltip).mouseover(function(e){
            $('#mytooltip').tooltip('close');
        });
        $(o.tooltip).mouseout(function(e){
        });         
    },
    close: function(e,o) {},
    show: { duration: 800 }
});

    $('#mytooltip').tooltip('open');//.delay(2000).tooltip('close');


});
4

2 回答 2

7

你可以这样做:

$(function () {
    $('#mytooltip').tooltip();

    $('#mytooltip').tooltip({
        open: function (e, o) {
            $(o.tooltip).mouseover(function (e) {
                $('#mytooltip').tooltip('close');
            });
            $(o.tooltip).mouseout(function (e) {});
        },
        close: function (e, o) {},
        show: {
            duration: 800
        }
    });

    $('#mytooltip').tooltip('open');
    setTimeout(function () {
        $('#mytooltip').tooltip('close'); //close the tooltip
    }, 3000); //but invoke me after 3 secs
});

小提琴。

于 2013-08-08T17:08:59.597 回答
0

这将与 Bootstrap 4 Tooltips 完美配合

$(document).ready( function () {
    $('[data-toggle="tooltip"]').tooltip();   
    setInterval(function () {
         $('[data-toggle="tooltip"]').tooltip('hide'); 
    }, 3000);
});

工具提示会在 3 秒后自动出现和消失。

我知道这个问题已经有 7 年历史了,但仍可能对某人有所帮助!

于 2021-04-17T08:00:07.733 回答