获取鼠标运动的轨迹

以下代码是在网面上把鼠标运动的轨迹给记录下来:
使用了jquery相关的一些方法,鼠标事件等。



var gesture = {};
var total_point = 0;
var number_column = 3;
var number_row = 3;
var bounds_x = [];
var bounds_y = [];


function getTotalHeight(){
if($.browser.msie){
return document.compatMode == "CSS1Compat"? document.documentElement.clientHeight : document.body.clientHeight;
}
else {
return self.innerHeight;
}
}

function getTotalWidth (){
if($.browser.msie){
return document.compatMode == "CSS1Compat"? document.documentElement.clientWidth : document.body.clientWidth;
}
else{
return self.innerWidth;
}
}


function get_pointer(e) {
var xx = e.originalEvent.x || e.originalEvent.layerX || 0;
var yy = e.originalEvent.y || e.originalEvent.layerY || 0;
var x_sequens="";
for(var i=0;i<number_column-1;i++){
if(xx>bounds_x[i]){
x_sequens+="1";
}else{
x_sequens+="0";
}
}

var y_sequens="";
for(var i=0;i<number_row-1;i++){
if(yy>bounds_y[i]){
y_sequens+="1";
}else{
y_sequens+="0";
}
}
//console.log(x_sequens+y_sequens);
//判断序列结果是否为上一次相同,不相同就记录下来,相同不记录
if(total_point==0 || gesture[total_point-1]!=x_sequens+y_sequens){
//console.log("impossible");
//console.log(gesture[total_point-1]);
//console.log(x_sequens+y_sequens);
gesture[total_point] = x_sequens+y_sequens;
total_point++;
}

//console.log(total_point);
}

function get_pointer_start() {

//全局变量初始化
gesture = {};
total_point = 0;
bounds_x = [];
bounds_y = [];

//取得当前窗口的大小
var do_width = getTotalWidth();
var do_height = getTotalHeight();
var unit_width=do_width/number_column;
for(var i=0;i<number_column;i++){
bounds_x[i] = (i+1)*unit_width;
}
var unit_height=do_height/number_row;
for(var i=0;i<number_row;i++){
bounds_y[i] = (i+1)*unit_height;
}
//采集数据
$(document).mousemove(get_pointer);
}

$(document).mousedown(get_pointer_start);
$(document).mouseup(function(){
$(this).unbind("mousemove",get_pointer);

if(total_point<=3){

return;
}

//计算最终结果
var result="";
for(var i=0;i<total_point;i++){
if(i==0){
result = gesture[i];
}else{
result = result+"-"+gesture[i];
}
}
//输出结果
console.log(result);
});
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值