【发布时间】:2014-02-04 04:48:39
【问题描述】:
我正在使用带有 div 元素的 jquery UI 工具提示,该元素在选择时会更改其背景图像。选择也是通过 jquery UI 完成的。 When hovering over the element the tooltip shows as expected, but when selecting the element the tooltip will close on mouse down and re-open on mouse-up, leading to an unwanted flicker.我怎样才能避免这种闪烁?我不喜欢在关闭工具提示时使用延迟,因为这会导致其他不良影响。
代码(有些简化):
$('#myDiv').tooltip({
tooltipClass: 'myTooltip',
track: true,
show: null,
hide: null,
position: { my: "left+15 top+25", at: "right bottom" }
});
setUpSelectable = function (id, filterType, selVar, funCB) {
$(id).selectable({
filter: filterType,
selected: function (event, ui) {
// Select new element
if (selVar.val == null || selVar.val.attr('id') !== $(ui.selected).attr('id'))
selVar.val = $(ui.selected);
else { // toggle already set element.
selVar.val.removeClass("ui-selected");
selVar.val = null;
}
},
stop: function (event, ui) {
// Remove all the other selected elements -> no multi select
if (selVar.val != null)
selVar.val.siblings().removeClass("ui-selected");
// callback
(funCB());
}
});
};
css:
.myTooltip {
position: absolute;
z-index: 9999;
width: 80px;
height: 20px;
box-shadow: -3px 3px 5px;
text-shadow: 1px 1px #000000;
border-radius: 6px;
text-align:center;
color: #9F9270;
background: none repeat 0 0 rgba(0, 0, 0, 0.9);
line-height: 20px;
vertical-align:middle;
font-size: 12px;
}
【问题讨论】:
-
把你的代码放在这里。 jQuery tooltip 没有你说的闪烁问题。所以,你一定是以错误的方式设置了这个工具提示。
-
我在上面的编辑中添加了基本代码。
-
如果你能分享一个 jsfiddle 那就太好了。
-
也许你可以通过从焦点事件中解除工具提示来避免闪烁。 $('#myDiv').tooltip().off("focusin focusout");
标签: jquery jquery-ui jquery-ui-tooltip