JS 获取鼠标坐标

本文介绍了一个使用JavaScript实现的简单网页,通过鼠标点击显示图片的功能,并提供了图片位置的实时更新。
<style type="text/css">        
     #imgFrame{ position:absolute; top:30%; left:40%; z-index:1000; display:none;}     
</style> 

<script type="text/javascript">         
function showOriginal(img,e) 
{
   //鼠标x坐标
// document.getElementById("imgFrame").style.top = mousePos(e).x;    //鼠标Y坐标
// document.getElementById("imgFrame").style.left = mousePos(e).y; // document.getElementById("imgFrame").style.zIndex=1000; // document.getElementById("imgFrame").style.position = "absolute"; document.getElementById("imgFrame").style.display = "block"; document.getElementById("imgbox").innerHTML = "<img src='" + img + "' />"; } function close() { document.getElementById("imgFrame").style.display = "none"; } //获取鼠标坐标 function mousePos(e){ var x,y; var e = e||window.event; return { x:e.clientX+document.body.scrollLeft+document.documentElement.scrollLeft, y:e.clientY+document.body.scrollTop+document.documentElement.scrollTop }; }; function test(e)
{

  document.getElementById("mjs").innerHTML = mousePos(e).x+','+mousePos(e).y;   

}; </script>

<img src='<%#Eval("picture")%>' width="100" height="50" onclick="showOriginal('<%#Eval("picture")%>',event);">

<div id="test" style="width:1000px;height:1000px;background:#ccc;" onmousemove="test(event)"></div>

转载于:https://www.cnblogs.com/lengv10/p/3656162.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值