js如何获取鼠标在某元素移动时~鼠标指针在元素中的坐标

js如何获取鼠标在某元素移动时~鼠标指针在元素中的坐标,第1张

稍等上代码!!

<html>

<head>

<script type="text/javascript">

function show_coords(event){

 var x = eventclientX;

 var y = eventclientY;

 var say = documentall("coords");

 sayinnerHTML = "X:"+x+" Y:"+y;

 saystyleposition = "absolute";

 saystyleleft = x + 30;

 saystyletop = y;

}

</script>

</head>

<body onmousemove="show_coords(event)">

<p id="coords"></p>

</body>

<html>

希望我的回答对你有用,有用就采纳!!!谢谢!

剪头像:

<script type="text/javascript" language="javascript">

<!--

//关于处理

var _cutMinW=48; //切片最小宽度

var _cutMinH=48; //切片最小高度

var _imgPath=getCookie('162100screenshotsImg'); //路径

function getCookie(name){

var arr=documentcookiematch(new RegExp("(^| )"+name+"=([^;])(;|$)"));

if(arr!=null && arr!=false) return decodeURIComponent(arr[2]);

return false;

}

function startP(){

//alert('示例已载入,此键暂不必用');

locationhref="starthtml";

}

function subCut(){

/

alert('\

实际宽度为'+Mathceil(_imgW)+'px\n\

实际高度为'+Mathceil(_imgH)+'px\n\

当前宽度为'+Mathceil(_nowW)+'px\n\

当前高度为'+Mathceil(_nowH)+'px\n\

截图X坐标为'+Mathceil(_pPoffsetWidth+1-_imgOoffsetLeft)+'px\n\

截图Y坐标为'+Mathceil(_pPoffsetHeight+1-_imgOoffsetTop)+'px\n\

截图宽度为'+Mathceil(_pOoffsetWidth-2)+'px\n\

截图高度为'+Mathceil(_pOoffsetHeight-2)+'px\n\

可将上述参数,转向后台处理。');

/

if(!_imgW || !_imgH || _imgO==null){

alert('加载出错!');

return false;

}

var f=documentcreateElement("form");

faction="i_upphp";

fmethod="post";

fstyledisplay='none';

finnerHTML='\

<input type="hidden" name="imgw" value="'+Mathceil(_imgW)+'" />\

<input type="hidden" name="imgh" value="'+Mathceil(_imgH)+'" />\

<input type="hidden" name="noww" value="'+Mathceil(_nowW)+'" />\

<input type="hidden" name="nowh" value="'+Mathceil(_nowH)+'" />\

<input type="hidden" name="px" value="'+Mathceil(_pPoffsetWidth+1-_imgOoffsetLeft)+'" />\

<input type="hidden" name="py" value="'+Mathceil(_pPoffsetHeight+1-_imgOoffsetTop)+'" />\

<input type="hidden" name="pw" value="'+Mathceil(_pOoffsetWidth-2)+'" />\

<input type="hidden" name="ph" value="'+Mathceil(_pOoffsetHeight-2)+'" />\

<input type="hidden" name="ptype" value="4" />\

';

documentbodyappendChild(f);

documentgetElementById('runSub')styledisplay='block';

fsubmit();

}

-->

</script

我只告诉你原理 代码自己写或者找下吧

页面上一个DIV display:absolute; 让他浮动起来

然后给此DIV一个鼠标按下事件 mousedown 当按下的时候 在给document文档一个鼠标移动事件

mousemove 当移动的时候 获取鼠标当前的坐标值 然后赋给DIV的TOP和LEFT 他就移动了

在给document一个鼠标抬起事件 mouseup 当d起的时候 把 document 的移动和抬起事件都取消了

至此就完成了一套拖拽动作

不过中间你还需要优化 *** 作

比如按下的位置相对于DIV边框的距离 这样才可以点击哪里 哪里就跟这移动 而不是只是左上角跟这移动。。。

首先应用百度地图API:

<script type="text/javascript" src=">

以上就是关于js如何获取鼠标在某元素移动时~鼠标指针在元素中的坐标全部的内容,包括:js如何获取鼠标在某元素移动时~鼠标指针在元素中的坐标、求javascript裁剪头像代码 简单一点的 只需要进行拖拽 *** 作获取到坐标和宽高 我自己另外写ajax函数提交、网页中怎么实现拖拽等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/9625401.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-30
下一篇 2023-04-30

发表评论

登录后才能评论

评论列表(0条)

保存