优雅的方式来关闭twitter bootstrap工具提示

时间:2013-09-10 09:02:14

标签: css twitter-bootstrap twitter-bootstrap-tooltip

我正在使用Twitter Bootstrap v3向登录按钮添加“无效登录”工具提示。这是我的代码:

    $('#login-form').submit(function(event) {
        event.preventDefault();
        $.post('/user/login', $(this).serialize(), function(data) {
            if (data.result == true) {
                window.location.replace('/');
            } else {
                var target = $('#login-form button[type="submit"]');
                target.tooltip({
                    title:      'Invalid login',
                    placement:  'bottom',
                    trigger:    'manual',
                    animation:  true
                });
                target.tooltip('show');
                setTimeout(function() {
                    target.tooltip('destroy');
                }, 2000);
            }
        }, 'json')
    });

特别是,我想知道是否有更好的方法来关闭工具提示。我希望我可以配置工具提示插件在几秒钟后自动淡出。或者,我尝试在调用'show'方法后链接.fade(2000),但这不起作用。

以上代码有效,我只是在寻找更优雅的替代方案。

1 个答案:

答案 0 :(得分:1)

您可以尝试在工具提示初始化

时输入参数“delay”

如下面的代码

            target.tooltip({
                title:      'Invalid login',
                placement:  'bottom',
                trigger:    'manual',
                animation:  true,
                delay: { show: 2000, hide: 3000 }
            });
相关问题