手机
当前位置:查字典教程网 >编程开发 >Javascript教程 >基于jquery的自定义鼠标提示效果 jquery.toolTip
基于jquery的自定义鼠标提示效果 jquery.toolTip
摘要:IE下效果Firefox或其它浏览器效果代码复制代码代码如下://版权酷车中国www.kuchechina.com//作者逐月zhuyue....

IE下效果

Firefox或其它浏览器效果

代码

复制代码 代码如下:

//版权 酷车中国 www.kuchechina.com

//作者 逐月 zhuyue.cnblogs.com

//演示 http://www.kuchechina.com/carstools/Default.aspx

jQuery.fn.toolTip = function() {

this.unbind().hover(

function(e) {

this.t = this.title;

this.title = '';

$('body').append( '<p id="p_toolTip"><img id="img_toolTip_Arrow" src="images/arrow.gif" />' + this.t + '</p>' );

var tip = $('p#p_toolTip').css({ "position": "absolute", "padding": "10px 5px 5px 10px", "left": "5px", "font-size": "14px", "background-color": "white", "border": "1px solid #a6c9e2","line-height":"160%", "-moz-border-radius": "5px", "-webkit-border-radius": "5px", "z-index": "9999"});

var target = $(this);

var position = target.position();

this.top = (position.top - 8); this.left = (position.left + target.width() + 5);

$('p#p_toolTip #img_toolTip_Arrow').css({"position": "absolute", "top": "8px", "left": "-6px" });

tip.css({"top": this.top+"px","left":this.left+"px"});

tip.fadeIn("slow");

},

function() {

this.title = this.t;

$("p#p_toolTip").fadeOut("slow").remove();

}

);

};

使用方法:

复制代码 代码如下:

<script type="text/javascript">

$(document).ready(function(){

$("#tootlsMain img[title]").toolTip();

});

</script>

可以利用jquery 选择器,选择带title属性的标签,当然可以适当的修改代码使适用带alt属性标签。

title属性支持简单html标签。如<br/>等。注意引号的使用

实现原理:

利用标签title属性,使hover事件取代默认鼠标事件,显示浮动层。this.unbind().hover 就是这句代码。jquery帮我们做好很多事情。堆积我们的现实代码就行。

程序员,文笔一般希望您能看懂。

代码下载

【基于jquery的自定义鼠标提示效果 jquery.toolTip】相关文章:

jQuery实现文本展开收缩特效

jQuery实现转动随机数抽奖效果的方法

Js和JQuery获取鼠标指针坐标的实现代码分享

JavaScript实现鼠标拖动效果的方法

jQuery实现鼠标经过图片变亮其他变暗效果

基于jquery实现下拉框美化特效

载入进度条 效果

jQuery实现表格行上下移动和置顶效果

详解Wondows下Node.js使用MongoDB的环境配置

jQuery实现的多屏图像图层切换效果实例

精品推荐
分类导航