如何修改我的工具提示javascript
How to amend my tooltip javascript?
每当我在链接上时,该脚本就会触发。我想改变它,当我在一个简单的div: <div id="personal"></div>
。谢谢你的帮助!
html:
<a href="#" class="fixedTip" title="Hello, I am aToolTip">Fixed Tooltip</a>
javascript: <script type="text/javascript">
$(function(){
$('a.normalTip').aToolTip();
$('a.fixedTip').aToolTip({
fixed: true
});
$('a.clickTip').aToolTip({
clickIt: true,
tipContent: 'Hello I am aToolTip with content from the "tipContent" param'
});
$('a.callBackTip').aToolTip({
clickIt: true,
onShow: function(){alert('I fired OnShow')},
onHide: function(){alert('I fired OnHide')}
});
});
</script>
主脚本:(function($) {
$.fn.aToolTip = function(options) {
/**
setup default settings
*/
var defaults = {
// no need to change/override
closeTipBtn: 'aToolTipCloseBtn',
toolTipId: 'aToolTip',
// ok to override
fixed: false,
clickIt: false,
inSpeed: 200,
outSpeed: 100,
tipContent: '',
toolTipClass: 'defaultTheme',
xOffset: 5,
yOffset: 5,
onShow: null,
onHide: null
},
// This makes it so the users custom options overrides the default ones
settings = $.extend({}, defaults, options);
return this.each(function() {
var obj = $(this);
/**
Decide weather to use a title attr as the tooltip content
*/
if(obj.attr('title')){
// set the tooltip content/text to be the obj title attribute
var tipContent = obj.attr('title');
} else {
// if no title attribute set it to the tipContent option in settings
var tipContent = settings.tipContent;
}
/**
Build the markup for aToolTip
*/
var buildaToolTip = function(){
$('body').append("<div id='"+settings.toolTipId+"' class='"+settings.toolTipClass+"'><p class='aToolTipContent'>"+tipContent+"</p></div>");
if(tipContent && settings.clickIt){
$('#'+settings.toolTipId+' p.aToolTipContent')
.append("<a id='"+settings.closeTipBtn+"' href='#' alt='close'>close</a>");
}
},
/**
Position aToolTip
*/
positionaToolTip = function(){
$('#'+settings.toolTipId).css({
top: (obj.offset().top - $('#'+settings.toolTipId).outerHeight() - settings.yOffset) + 'px',
left: (obj.offset().left + obj.outerWidth() + settings.xOffset) + 'px'
})
.stop().fadeIn(settings.inSpeed, function(){
if ($.isFunction(settings.onShow)){
settings.onShow(obj);
}
});
},
/**
Remove aToolTip
*/
removeaToolTip = function(){
// Fade out
$('#'+settings.toolTipId).stop().fadeOut(settings.outSpeed, function(){
$(this).remove();
if($.isFunction(settings.onHide)){
settings.onHide(obj);
}
});
};
/**
Decide what kind of tooltips to display
*/
// Regular aToolTip
if(tipContent && !settings.clickIt){
// Activate on hover
obj.hover(function(){
// remove already existing tooltip
$('#'+settings.toolTipId).remove();
obj.attr({title: ''});
buildaToolTip();
positionaToolTip();
}, function(){
removeaToolTip();
});
}
// Click activated aToolTip
if(tipContent && settings.clickIt){
// Activate on click
obj.click(function(el){
// remove already existing tooltip
$('#'+settings.toolTipId).remove();
obj.attr({title: ''});
buildaToolTip();
positionaToolTip();
// Click to close tooltip
$('#'+settings.closeTipBtn).click(function(){
removeaToolTip();
return false;
});
return false;
});
}
// Follow mouse if enabled
if(!settings.fixed && !settings.clickIt){
obj.mousemove(function(el){
$('#'+settings.toolTipId).css({
top: (el.pageY - $('#'+settings.toolTipId).outerHeight() - settings.yOffset),
left: (el.pageX + settings.xOffset)
});
});
}
}); // END: return this
};
不妨试试:
$('div').aToolTip(); // For any div
$('div#myID').aToolTip(); // For div with id="myID"
$('div.myClass').aToolTip(); // For div with class="myClass"
相关文章:
- 单元格的工具提示或标题不显示超过2000个字符
- 禁用NVD3 multiBarHorizontalChart中0值的工具提示
- 如何更改已显示的工具提示
- 语义UI中格式化的工具提示
- 如何在Google Geochart图表的工具提示文本中添加新行
- 如何将数据标签与数据一起传递,以便在高图中的工具提示中显示
- 显示禁用单选按钮引导程序3的工具提示
- Twitter Bootstrap - 带有动态变化插入的工具提示
- 在Highcharts中,使特定点的工具提示始终可见且动态,我将更改其点
- 阻止我的工具提示闪烁
- 如何删除默认工具提示并保留我自己的工具提示的内容
- 为什么我的工具提示没有显示,如果我可以在源代码中看到它
- 根据我悬停的圆圈显示相应的工具提示文本
- 为什么我的工具提示的延迟时间选项不起作用?
- 我想为选中的项目附加一个点击事件,并在jquery的自动完成控件中显示鼠标上的工具提示
- 为什么我的工具提示在Firefox中闪烁而不是Chrome ?
- 如何修改我的工具提示javascript
- 我如何添加一些文本到NVD3离散条形图的工具提示
- 如何使我的工具提示出现在我的链接下面,即使我的链接在页面的底部
- 我不知道如何将我创建的工具提示连接到图像映射