jquery 判断鼠标移动方向 如何判断鼠标移动方向,了解思想是利用e.clientX记住两次的鼠标坐标,再把二者相减,可以得出鼠标移动方向,问题是弄了很久也不见得效果,希望回复者不要把刚开始的x坐标置为0.懂得请帮忙!不甚感激! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 http://topic.csdn.net/u/20110411/11/02ed0e54-64a7-4fdf-8348-20fb3c3b5247.html稍微修改下,如果只想计算鼠标移动方向的话,数组中只需要记录一个坐标,onmousemove事件触发时,用当前坐标跟数组中记录的坐标比较一下,计算好方向后更新数组。 如果外层容器有relative 或 absolute 会有些影响的 的确,有用绝对定位,因为想做成像iphone那样的滑动效果! <!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></head><style type="text/css">html,body { height:100%; }</style><body><script type="text/javascript">var arrPos = new Array();window.onload = function() { document.getElementsByTagName('body')[0].onmousemove = function(e) { var x = e.clientX, y = e.clientY; //判断鼠标运行方向 var direction = ''; if (arrPos.length > 0) { if (x > arrPos[0][0]) { if (y == arrPos[0][1]) direction = '右'; else { if (y > arrPos[0][1]) direction = '右下'; else direction = '右上'; } } else { if (x == arrPos[0][0]) { if (y < arrPos[0][1]) direction = '上'; else { if (y > arrPos[0][1]) direction = '下'; } } else { if (y == arrPos[0][1]) direction = '左'; else { if (y > arrPos[0][1]) direction = '左上'; else direction = '左下'; } } } } if (arrPos.length < 1) arrPos.push(Array(x,y)); else { arrPos[0][0] = x; arrPos[0][1] = y; document.getElementById('direction').innerHTML = direction; } }}</script><div id="direction"></div></body></html> 求第三方上传控件,最好是带进度条的如SWFFileUpload(有实例最佳) 请问js中.能否获取和设置浏览器对话框的值??有心人看哈.没分了! jquery hover事件如何不冒泡? 腾讯的javascript到底有多强? 问一句javascipt正则 attachEvent方法,对于有参数传递的函数如何使用??? 用javascript怎么能到input框的类型! 如何使title属性弹出时间变长一点 怎么中断jscript的程序 kendo treeview 获取父节点值的问题 为什么外部调用js方法有时会报找不到错误? 遇到个很奇怪的问题,求指点。
稍微修改下,如果只想计算鼠标移动方向的话,数组中只需要记录一个坐标,onmousemove事件触发时,用当前坐标跟数组中记录的坐标比较一下,计算好方向后更新数组。
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<style type="text/css">
html,body { height:100%; }
</style>
<body>
<script type="text/javascript">
var arrPos = new Array();
window.onload = function() {
document.getElementsByTagName('body')[0].onmousemove = function(e) {
var x = e.clientX, y = e.clientY;
//判断鼠标运行方向
var direction = '';
if (arrPos.length > 0) {
if (x > arrPos[0][0]) {
if (y == arrPos[0][1]) direction = '右';
else {
if (y > arrPos[0][1]) direction = '右下';
else direction = '右上';
}
}
else {
if (x == arrPos[0][0]) {
if (y < arrPos[0][1]) direction = '上';
else {
if (y > arrPos[0][1]) direction = '下';
}
}
else {
if (y == arrPos[0][1]) direction = '左';
else {
if (y > arrPos[0][1]) direction = '左上';
else direction = '左下';
}
}
}
}
if (arrPos.length < 1) arrPos.push(Array(x,y));
else {
arrPos[0][0] = x;
arrPos[0][1] = y;
document.getElementById('direction').innerHTML = direction;
}
}
}
</script>
<div id="direction"></div>
</body>
</html>