jQuery qTip 插件,如何拆分'title'属性和应用样式
我尝试在这里使用 qTip jQuery 插件: http://craigsworks.com/projects/ qtip2/demos/#mouse
我得到了基于演示的代码,但我希望能够从 TITLE 属性“分解”内容,并拥有第一项数组是“标题”,第二项是“内容”。
我有以下代码:
<script>
$(document).ready(function()
{
$('.tip3').qtip({
content: {
text: function(api) {
var titleAttr = $(this).attr('title');
var titleAttrArray = titleAttr.split(' :: ');
return titleAttrArray[1];
},
title: {
text: function(api) {
// Retrieve content from TITLE attribute of the $('.selector') element
// return $(this).attr('title');
return titleAttrArray[0];
}
}
},
position: {
my: 'top left',
target: 'mouse',
viewport: $(window), // Keep it on-screen at all times if possible
adjust: {
x: 10, y: 10
}
},
hide: {
fixed: true // Helps to prevent the tooltip from hiding ocassionally when tracking!
},
style: 'ui-tooltip-youtube'
});
});
</script>
<div class="box tip3" title="Some cool title here! :: Some subheader here?">
<h3>Hover over this box to see mouse tracking in action</h3>
</div>
仅供参考,下面的代码只需获取 TITLE 并且不对其执行任何操作即可完美运行:
<script>
$(document).ready(function()
{
$('.tip2').qtip({
content: {
text: 'I really like owls!',
title: {
text: function(api) {
// Retrieve content from TITLE attribute of the $('.selector') element
return $(this).attr('title');
}
}
},
position: {
my: 'top left',
target: 'mouse',
viewport: $(window), // Keep it on-screen at all times if possible
adjust: {
x: 10, y: 10
}
},
hide: {
fixed: true // Helps to prevent the tooltip from hiding ocassionally when tracking!
},
style: 'ui-tooltip-youtube'
});
});
</script>
任何想法/见解都很棒!仍然是一个试图弄清楚 jQuery 的新手:)。
I'm trying to use the qTip jQuery plugin here: http://craigsworks.com/projects/qtip2/demos/#mouse
I got the code to work based on the demo, but I'd like to be able to "explode" the content from the TITLE attribute, and have the first item of the array be the "header" and the second item be the "content."
I have the following code:
<script>
$(document).ready(function()
{
$('.tip3').qtip({
content: {
text: function(api) {
var titleAttr = $(this).attr('title');
var titleAttrArray = titleAttr.split(' :: ');
return titleAttrArray[1];
},
title: {
text: function(api) {
// Retrieve content from TITLE attribute of the $('.selector') element
// return $(this).attr('title');
return titleAttrArray[0];
}
}
},
position: {
my: 'top left',
target: 'mouse',
viewport: $(window), // Keep it on-screen at all times if possible
adjust: {
x: 10, y: 10
}
},
hide: {
fixed: true // Helps to prevent the tooltip from hiding ocassionally when tracking!
},
style: 'ui-tooltip-youtube'
});
});
</script>
<div class="box tip3" title="Some cool title here! :: Some subheader here?">
<h3>Hover over this box to see mouse tracking in action</h3>
</div>
Just for reference, the code below works perfectly fine by just fetching TITLE and not doing anything with it:
<script>
$(document).ready(function()
{
$('.tip2').qtip({
content: {
text: 'I really like owls!',
title: {
text: function(api) {
// Retrieve content from TITLE attribute of the $('.selector') element
return $(this).attr('title');
}
}
},
position: {
my: 'top left',
target: 'mouse',
viewport: $(window), // Keep it on-screen at all times if possible
adjust: {
x: 10, y: 10
}
},
hide: {
fixed: true // Helps to prevent the tooltip from hiding ocassionally when tracking!
},
style: 'ui-tooltip-youtube'
});
});
</script>
Any ideas/insights would be fantastic! Still a newbie trying to figure jQuery out :).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您无法在标题函数中访问
titleAttrArray
,因为它不在范围内。只需处理两次标题属性或使用其他属性即可。You can't access
titleAttrArray
in your title function as its not in scope. Just process the title attribute twice or use another attribute.