您是否需要使用 ID 数组?我建议最好在所有提示容器和内容元素上设置一个类,这应该意味着您只需要创建一个FloatingTips()
. 例如:
<div class="tipContainer">
<p>A second tip</p>
<p><a href="#">Let me see!</a></p>
<div class="tipContent" style="display: none;">
<p>Here is another tip.</p>
</div>
</div>
<div class="tipContainer">
<p>A second tip</p>
<p><a href="#">Let me see!</a></p>
<div class="tipContent" style="display: none;">
<p>Here is another tip.</p>
</div>
</div>
更新后的调用FloatingTips
将包含对 HTML 中设置的 tipContainer 和 tipContent 类的更新引用。拉取内容的功能已稍作更改,以便它在具有“tipContent”类的元素中查找内容。
new FloatingTips('.tipContainer', {
// Content can be a string (an attribute name) or a function.
// If it's a function, it can returns string or HTML elements.
content: function(tipContainer) {
return $(tipContainer).getElement('.tipContent');
},
html: true, // I want that content is interpreted as HTML
center: false, // I do not want to center the tooltip
arrowOffset: 16, // Arrow is a little more the the right
offset: { x: 10 }, // Position offset {x, y}
position: 'bottom',
});
这是一个实际的例子 - http://jsfiddle.net/pH3BB/1/
希望这可以帮助!
克雷格