San*_*til 9 html jquery-ui hide jquery-ui-tooltip
我有两个按钮+和-.当我点击+按钮时,我在父div中添加一个div,并且当我再次单击+按钮时,我想在该div上显示工具提示然后我再添加一个div并且只想在第二个div上显示工具提示.最高7 div也是如此.
目前我正在做同样的事情,但是当我添加多个div时,工具提示将不会隐藏前一个按钮,并且仍然存在.所以最后我看到所有7个工具提示,但我应该只看到最后一个div工具提示.
我试图在延迟一段时间后隐藏它,但即使它不起作用.
这是我的代码.
function init(){
for(var divCount = 1; divCount <= fanSpeed; divCount++){
$('#temperature_bar').append('<div style="float:left" data-tooltip-id="'+divCount+'" id="speed_"'+divCount +'" class="trigger climate-fan-bar" onclick="\buttonTempraturePressed(this.id)\" title="<div class="row row-thumbnail" id="box-search"><div class="thumbnail text-center"><img width="50" height="50" src="images/fan_speed_bg_center_popup.png" class="img-responsive"><div class="caption"><span class="tooltip-text-size">' + divCount + '</span></div></div></div></div>' );
showTooltips("speed_"+divCount);
}
}
function showTooltips(clicked_id){
//show
$(clicked_id).on('click', '.trigger', function () {
$(this).addClass("on");
$(this).tooltip({
hide: { effect: "flip", duration: 1000 },
items: '.trigger.on',
position: {
my: "top",
at: "top",
collision: "flip"
}
});
$(this).trigger('mouseenter');
});
/*$(clicked_id).on('click', '.trigger.on', function () {
$(this).tooltip('close');
$(this).removeClass("on");
});*/
//prevent mouseout and other related events from firing their handlers
$(".trigger").on('mouseout', function (e) {
e.stopImmediatePropagation();
});
}
Run Code Online (Sandbox Code Playgroud)
这是一个可能的解决方案。利用items和content选项,您可以调整内容,而不是尝试通过title属性传递它。
工作示例: https: //jsfiddle.net/Twisty/cfd6z8db/
超文本标记语言
<div style="padding:20px; display: block;">
<div id="temperature_bar">
</div>
</div>
<div style="padding:20px; display: block;">
<label>Speed</label>
<button id="decSpeed" title="Decrease">-</button>
<button id="incSpeed" title="Increase">+</button>
</div>
Run Code Online (Sandbox Code Playgroud)
CSS
.item {
border-style: solid;
border-width: 1px 1px 1px 0;
border-color: #ccc;
padding: .25em .5em;
cursor: pointer;
}
.item:nth-child(1) {
border-left-width: 1px;
}
.row-thumbnail .caption {
width: 100%;
text-align: center;
}
Run Code Online (Sandbox Code Playgroud)
jQuery
function showToolTips(obj) {
if (obj.hasClass("on")) {
// Hide ToolTip
obj.removeClass("on");
obj.tooltip("close");
} else {
// Show ToolTip
obj.addClass("on");
obj.tooltip("open");
}
}
function addItem() {
var divCount = $(".item").length + 1;
if (divCount == 8) {
return false;
}
var img = "https://dummyimage.com/50x50/000000/fff";
var item = $("<div>", {
id: "speed-" + divCount,
class: "trigger item",
"data-tip-content": img + "|" + divCount,
"data-tip-id": divCount,
})
.css("float", "left");
item.html(divCount);
item.tooltip({
disabled: true,
hide: {
effect: "flip",
duration: 1000
},
position: {
my: "center bottom+5",
at: "center top",
collision: "flip"
},
items: "[data-tip-content]",
content: '<div class="row row-thumbnail" id="box-search"><div class="thumbnail text-center"><img width="50" height="50" src="' + item.data("tip-content").split("|")[0] + '" class="img-responsive"><div class="caption"><span class="tooltip-text-size">' + item.data("tip-content").split("|")[1] + '</span></div></div>'
});
$('#temperature_bar').append(item);
}
// Make Items
function init() {
var c = 5;
var divCount = 1;
for (divCount; divCount <= c; divCount++) {
var item = $("<div>", {
id: "speed-" + divCount,
class: "trigger item",
"data-tip-content": "https://dummyimage.com/50x50/000000/fff" + "|" + divCount,
"data-tip-id": divCount,
})
.css("float", "left");
item.html(divCount);
item.tooltip({
disabled: true,
hide: {
effect: "flip",
duration: 1000
},
position: {
my: "center bottom+5",
at: "center top",
collision: "flip"
},
items: "[data-tip-content]",
content: '<div class="row row-thumbnail" id="box-search"><div class="thumbnail text-center"><img width="50" height="50" src="' + item.data("tip-content").split("|")[0] + '" class="img-responsive"><div class="caption"><span class="tooltip-text-size">' + item.data("tip-content").split("|")[1] + '</span></div></div>'
});
$('#temperature_bar').append(item);
}
}
$(function() {
init();
$(".trigger").on('mouseout', function(e) {
if ($(this).hasClass("on")) {
$(this).removeClass("on");
$(this).tooltip("close");
}
});
$("#temperature_bar").on("click", ".trigger", function() {
console.log("Click Triggered. Executing 'showToolTips()'.");
showToolTips($(this));
});
$("#decSpeed").click(function() {
$("#temperature_bar .item").last().remove();
});
$("#incSpeed").click(addItem);
});
Run Code Online (Sandbox Code Playgroud)
当使用像 之类的位置时{ my: "top", at: "top", collision: "flip" },这会导致某种奇怪的加载问题。我使用了不同的立场,似乎解决了这个问题。
您的帖子没有给出非常有力的示例,因此我创建了一些示例按钮。该disable选项也很有帮助,这确保了它们不会在mouseover事件中显示。它还允许我们控制open和close。
我将所有内容项打包到一个数据属性中。我用一根管子 ( |) 将其分开,这样它们就可以全部集中在一个点上,但以后可以轻松使用。
单击按钮,就会出现提示。再次点击它,它就隐藏了。如果您将鼠标移开,效果也会相同。
如果您需要更多信息,请使用更好的示例更新您的帖子。
| 归档时间: |
|
| 查看次数: |
726 次 |
| 最近记录: |