我正在尝试遍历 tooltipabble
元素,并在每个元素上显示工具提示
在一段时间内,隐藏之前显示的一个。
显示它们都很好,但我对如何隐藏前一个有问题。
我正在使用 bootstrap
tooltip('show') 和 tooltip('hide') 方法,所以我将元素包装在 $()
(function(){
var i = 0;
var tt = $('[data-toggle="tooltip"]');
setInterval(function(){
// if(oldTip) $(oldTip).tooltip('hide'); // not working
var tip = tt[i++];
$(tip).tooltip('show');
// tried saving old instance here but that didn't work
// oldTip = tip;
if(i >= tt.length) i = 0;
}, 2000);
})();
最佳答案
(function () {
var i = 0;
var tt = $('[data-toggle="tooltip"]');
setInterval(function () {
// hide all tooltips
tt.tooltip('hide');
// show the one we want (use toggle - as show will compete with hide)
$(tt[i++ % tt.length]).tooltip('toggle');
}, 2000);
})();
关于javascript - 循环 Bootstrap 工具提示元素,同时显示和隐藏它们,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28844742/