受网友启发,用js写了这个地震监控页面:就是用mousemove监控鼠标,如果捕捉到鼠标在快速的来回摆动,就提示地震警告
大家帮忙测试以下,如果有豆浆机,果汁机的帮忙把鼠标放到上面模拟测试
各项参数设置还在调整中,对于程序如果有什么改善建议,希望大家提出来
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
Code
<script>
var times = 0;
var ms = new Date();
var prex =0;
var pretoright=false;
var level =0;
function trackEarthQuake(){
var curx = event.screenX;
var toright ;
if(curx>prex){
level += curx-prex;
toright=true;
} else {
toright=false;
}
prex = curx;
if(pretoright!=toright){
times ++;
}
pretoright=toright;
var curms=new Date();
if(times>=10){
times=0;
intervalms = curms-ms;
if(intervalms<=1600){
alert("有地震!快跑!地震级别为"+Math.round(Math.log(level)));
}
ms=curms;
level=0;
}
}
</script>
<body onmousemove="trackEarthQuake()">
</body>