QTip2 多个元素,相同的工具提示
我有一个页面,我在其中动态创建需要工具提示的元素。
我尝试了几种不同的方法,并在网上寻找一些答案,但无济于事。
截至目前,我有这样的:
var $links = $('a.link');
var len = $links.length;
for(var i = 0; i < len; i++){
var $ele = $($links[i]);
$ele.qtip({
id: 'editLink',
overwrite: false,
content: {
text: $linkEditor,
title: {
text: 'Edit Link',
button: true
}
},
position: {
my: 'top center',
at: 'bottom center',
viewport: $(window)
},
show: {
event: 'mouseover',
solo: true
},
hide: false,
style: {classes: 'ui-tooltip-shadow ui-tooltip-red'}
});
}
我正在寻找的是让所有这些元素使用完全相同的工具提示的某种方法。我希望它们都使用完全相同的内容(在本例中为单个表单)并以完全相同的方式引用工具提示(通过 id 为“ui-tooltip-editLink”的工具提示元素)。
根据我所拥有的,它目前正确创建了第一个工具提示,但如果我添加一个新元素并重新分配工具提示,它会为新元素创建一个具有不同 id 的全新工具提示。
有谁知道实现多个元素、相同工具提示方法的某种方法?
I have a page in which I dynamically create elements that need tooltips.
I've tried a few different approaches and looked online for some answers to no avail.
As of now, I have this:
var $links = $('a.link');
var len = $links.length;
for(var i = 0; i < len; i++){
var $ele = $($links[i]);
$ele.qtip({
id: 'editLink',
overwrite: false,
content: {
text: $linkEditor,
title: {
text: 'Edit Link',
button: true
}
},
position: {
my: 'top center',
at: 'bottom center',
viewport: $(window)
},
show: {
event: 'mouseover',
solo: true
},
hide: false,
style: {classes: 'ui-tooltip-shadow ui-tooltip-red'}
});
}
What I'm looking for is some way to have all of these elements use the exact same tooltip. I want them all to use the exact same content (in this case a single form) and reference the tooltip in the exact same way (by the tooltip element with id 'ui-tooltip-editLink').
With what I have, it currently creates the first tooltip correctly, but if I add a new element and reassign tooltips, it creates a whole new tooltip with a different id for the new element.
Does anyone know some way of accomplishing a multiple elements, same tooltip approach?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我已经弄清楚如何让一个工具提示 div 被许多工具提示图像共享(如果有人觉得它很方便的话)
如果您未能将 .html() 放在那里,您将看到共享的工具提示显示一旦,然后当您从另一个图像激活它时,它将不再对第一个图像起作用...
tooltipBearing 是在页面中的某些图像上设置的类。
tooltipDiv 是包含工具提示内容的 div 的 ID。
I've figured out how to have one tooltip div be shared by many tooltip images if anyone finds it handy
If you fail to put the .html() on there, you will see the shared tooltip show up once, and then when you activate it from another image, it will no longer work for the first one...
The tooltipBearing is a class set on some images in the page.
tooltipDiv is the ID of the div containing your tooltip content.
为了在动态创建的元素中使用
qtip
,您需要在元素初始化期间包含qtip
。例如
In order to use
qtip
in dynamically created element, you need to includeqtip
during the element initialization.e.g.
遗憾的是,看起来我们需要为每个悬停/单击元素克隆工具提示元素。
Craig 在 GitHub 问题中提到了这一点: https://github.com/Craga89/qTip2/issues/173
Sadly it looks like we need to clone the Tooltip element for each of the hover/click elements.
Craig mentions this in the GitHub issue: https://github.com/Craga89/qTip2/issues/173
这就是我所做的。我将工具提示附加到一个独特的元素上。然后我的所有其他需要相同工具提示的元素只会触发唯一元素的工具提示显示:
但是,所有工具提示将显示在固定位置。对于我来说这不是问题,因为我使用工具提示作为模式。您必须通过自定义
事件
方法来管理工具提示位置。This is what I did. I attached the my tooltip on a unique element. And then all of my other elements that need the same tooltip will just trigger the unique element's tooltip display:
However, the all of your tooltips will be displayed in a fixed position. This was not a problem in my case because I was using the tooltip as modal. You will have to manage the tooltip position via cutom
event
methods.根据user738048的回答,我的工作解决方案是这样的:
在我的例子中,包含文本取自
data-tooltipid
属性;我的href
和onclick
属性已被删除,因为它们已被工具提示废弃。Based on the answer of user738048, my working solution is like this:
In my case, the id of the HTML element containing the text is taken from a
data-tooltipid
attribute; myhref
andonclick
attributes are removed since they are obsoleted by the tooltip.