帝王谷资源网 Design By www.wdxyy.com
思路

1.首先要定位实现这种效果的元素 ,本次通过class

2.如果是动态显示不同的提示内容,需设置title

3.通过JQ给定位到元素加上 mouseover 和mouseout 事件

4.再完善下,弹出框跟随鼠标在目标元素上移动

5.再把 mouseover 、mouseout 合并成 hover
复制代码 代码如下:
//页面加载完成
$(function () {
    var x = 10;
    var y = 20; //设置提示框相对于偏移位置,防止遮挡鼠标
    $(".prompt").hover(function (e) {  //鼠标移上事件
        this.myTitle = this.title; //把title的赋给自定义属性 myTilte ,屏蔽自带提示
        this.title = "";
&nbsp; &nbsp; &nbsp; &nbsp; var tooltipHtml = "<div id='tooltip'>" + this.myTitle + "</div>"; //创建提示框
&nbsp; &nbsp; &nbsp; &nbsp; $("body").append(tooltipHtml); //添加到页面中
&nbsp; &nbsp; &nbsp; &nbsp; $("#tooltip").css({
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "top": (e.pageY + y) + "px",
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "left": (e.pageX + x) + "px"
&nbsp; &nbsp; &nbsp; &nbsp; }).show("fast"); //设置提示框的坐标,并显示
&nbsp; &nbsp; }, function () { &nbsp;//鼠标移出事件
&nbsp; &nbsp; &nbsp; &nbsp; this.title = this.myTitle; &nbsp;//重新设置title
&nbsp; &nbsp; &nbsp; &nbsp; $("#tooltip").remove(); &nbsp;//移除弹出框
&nbsp; &nbsp; }).mousemove(function (e) { &nbsp; //跟随鼠标移动事件
&nbsp; &nbsp; &nbsp; &nbsp; $("#toolti").css({ "top": (e.pageY + y) + "px",
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "left": (e.pageX + x) + "px"
&nbsp; &nbsp; &nbsp; &nbsp; });
&nbsp; &nbsp; });
});
标签:
鼠标,弹出,提示框

帝王谷资源网 Design By www.wdxyy.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
帝王谷资源网 Design By www.wdxyy.com