简体   繁体   English

Bootstrap 工具提示 - 动态延迟

[英]Bootstrap tooltips - dynamic delay

How to dynamically change tooltip delay in Bootstrap?如何在 Bootstrap 中动态更改工具提示延迟?

I have div with buttons, when i .mouseenter() on it first time i want a delay of 500ms, but after 500ms i want to change it to 100ms.我有带按钮的 div,当我第一次使用.mouseenter()时,我希望延迟 500 毫秒,但在 500 毫秒后我想将其更改为 100 毫秒。 On .mouseleave() i want it back to 500ms..mouseleave()我希望它回到 500 毫秒。

Its working but with tooltip('destroy') its killing already shown tooltip.它可以工作,但是使用 tooltip('destroy') 它的杀死已经显示了工具提示。

How to figure it out?如何弄清楚?

here is fiddle: https://jsfiddle.net/0nep4tk3/2/这是小提琴: https : //jsfiddle.net/0nep4tk3/2/

var $btns = $(".buttons").find('button');
$(".buttons").on('mouseenter', function(e){
        setTimeout(function(){
            setTooltips({show:100, hide:10});
        },750);  
    }).on('mouseleave',function(){
        setTooltips({show:500, hide:100});
    })


    function setTooltips(opt){
        $btns.tooltip('destroy');
        $btns.tooltip({
            trigger:'hover',
            delay:{show:opt.show, hide:opt.hide},
            container:'body',
        }); 
    } 

A nice example you can find on https://webflow.com/ , in their editor they have very nice tooltips for buttons.你可以在https://webflow.com/ 上找到一个很好的例子,在他们的编辑器中,他们有非常好的按钮工具提示。

EDIT编辑

I edited fiddle for better ms and feeling what i mean.我编辑了小提琴以获得更好的女士并感受我的意思。 So, this is what i got: I hover BTN1 and after 500ms tooltip will appear but also after 1s i change all tooltip ms ( so i need use 'destroy') and then tooltip for BTN1 which one should still be visible (beouse my mouse is over BTN1 ) will disapear.所以,这就是我得到的:我悬停 BTN1 并在 500 毫秒后会出现工具提示,但在 1 秒后我更改了所有工具提示 ms(所以我需要使用“销毁”)然后 BTN1 的工具提示应该仍然可见(因为我的鼠标结束 BTN1 ) 将消失。 I want him to stay after tooltips ms change.我希望他在工具提示 ms 更改后留下来。 I just want to get nice tooltip feeling for buttons.我只想为按钮获得不错的工具提示感觉。

Without having to destroy and recreate tooltips every time you can edit the delay option.每次编辑延迟选项时都不必销毁和重新创建工具提示。
If i have understood correctly your request, this should do:如果我正确理解了您的要求,则应该这样做:

var $btns = $(".buttons").find('button');

$btns.tooltip({
    trigger:'hover',
    delay: {show: 500, hide: 500},
    container:'body',
}); 
$(".buttons").on('mouseenter', function(e){
    setTimeout(function(){
        console.log("100");
        setTooltips({show: 100, hide: 100});
    },500); 
}).on('mouseleave',function(e){
    console.log("500");
    setTooltips({show: 500, hide: 500});
});


function setTooltips(opt){
    $btns.each(function(){
        $(this).data('bs.tooltip').options.delay=opt;
        console.log($btns.data('bs.tooltip').options.delay);
    })
} 

I have left the console.log for testing purposes, you can safely remove them if you don't need them anymore.我已将 console.log 留作测试目的,如果您不再需要它们,您可以安全地删除它们。
If the values i put are incorrect you can easily tweak them but the main logic should be this:如果我输入的值不正确,您可以轻松调整它们,但主要逻辑应该是这样的:

  1. At first, delay is 500ms.起初,延迟是500ms。

  2. When you mouseenter on the div the delay will be set to 100ms after 500ms当你mouseenter在DIV上的延迟将500毫秒后设置为100ms

  3. when you mouseover the delay will be back to 500ms当您将mouseover ,延迟将回到 500 毫秒

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM