jQuery学习笔记4——event.pageX()方法/event.pageY()方法

该方法的作用是获取到光标相对于页面的X坐标和Y坐标。网页中常用的title提示效果就和这两个属性有关。

<! DOCTYPE html PUBLIC  " -//W3C//DTD XHTML 1.0 Transitional//EN "   " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd " >
< html xmlns = " http://www.w3.org/1999/xhtml " >
< head >
< meta http - equiv = " Content-Type "  content = " text/html; charset=utf-8 "   />
< title > 超链接提示效果 </ title >
< script type = " text/javascript "  src = " jquery-1.2.6.min.js " ></ script >
< script type = " text/javascript " >
ExpandedBlockStart.gifContractedBlock.gif    $(document).ready(function()
{
        var x
=10;
        var y
=20;
ExpandedSubBlockStart.gifContractedSubBlock.gif        $(
"a.tooltip").mouseover(function(e){
            
this.myTitle = this.title;
            
this.title="";
            var tooltip 
= "<div id='tooltip'>" + this.myTitle + "</div>";    
            $(
"body").append(tooltip);
            $(
"#tooltip")
ExpandedSubBlockStart.gifContractedSubBlock.gif                .css(
{
                    
"top":(e.pageY+y)+"px",
                    
"left":(e.pageX+x)+"px"
                }
).show("fast");
ExpandedSubBlockStart.gifContractedSubBlock.gif        }
).mouseout(function(){
            $(
"#tooltip").remove();
            
this.title = this.myTitle;
        }
)
    }
)    
</ script >
< style type = " text/css " >
ExpandedBlockStart.gifContractedBlock.gifbody
{  }
ExpandedBlockStart.gifContractedBlock.gif#tooltip
{ position:absolute; width:120px;height:22px; line-height:22px; border:1px solid #ccc; background:#f6f6f6; font-size:12px;}
</ style >
</ head >
< body >
< p >< a href = " # "   class = " tooltip "  title = " 这是我的超链接提示1 " > 提示 </ a ></ p >
< p >< a href = " # "   class = " tooltip "   title = " 这是我的超链接提示2 " > 提示 </ a ></ p >
< p >< a hef = " # "  title = " 这是自带提示1 " > 自带提示1 </ a ></ p >
< p >< a hef = " # "  title = " 这是自带提示2 " > 自带提示2 </ a ></ p >
</ body >
</ html >

转载于:https://www.cnblogs.com/guopei/articles/1520648.html

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值