|
@@ -314,6 +314,7 @@ $(function(){
|
|
|
shake:function(){
|
|
|
if (window.DeviceMotionEvent) {
|
|
|
window.addEventListener('devicemotion', deviceMotionHandler, false);
|
|
|
+ alert("shake");
|
|
|
}
|
|
|
else {
|
|
|
alert('您的设备不支持!');
|
|
@@ -329,6 +330,8 @@ $(function(){
|
|
|
strong,
|
|
|
mine_bonus_sn=$('#mine_bonus').val();
|
|
|
function deviceMotionHandler(eventData) {
|
|
|
+
|
|
|
+ alert("shake event");
|
|
|
var acceleration = eventData.accelerationIncludingGravity;
|
|
|
var curTime = new Date().getTime();
|
|
|
var diffTime = curTime - last_update;
|
|
@@ -337,8 +340,12 @@ $(function(){
|
|
|
x = acceleration.x;
|
|
|
y = acceleration.y;
|
|
|
z = acceleration.z;
|
|
|
+ alert("shake event x=" + x + " y=" + y);
|
|
|
var speed = Math.abs(x + y + z - last_x - last_y - last_z) / diffTime * 10000;
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+ strong = 0;
|
|
|
if (speed>3000&&speed <= 4500) {
|
|
|
strong=1;
|
|
|
}
|
|
@@ -351,38 +358,41 @@ $(function(){
|
|
|
if(speed>7500&&speed <= 9000) {
|
|
|
strong=4;
|
|
|
}
|
|
|
- if(speed>9000&&speed <= 10500) {
|
|
|
+ if(speed>9000) { //&&speed <= 10500
|
|
|
strong=5;
|
|
|
}
|
|
|
|
|
|
- last_x = x;
|
|
|
- last_y = y;
|
|
|
- last_z = z;
|
|
|
+ if (strong == 0) return;
|
|
|
+
|
|
|
var speed_strongs={
|
|
|
strength:strong,
|
|
|
bonus_sn:mine_bonus_sn
|
|
|
};
|
|
|
$.ajax({
|
|
|
type:'get',
|
|
|
- url:"http://a.lrlz.com/mobile/index.php?op=shake&act=bonusex&client_type=ajax",
|
|
|
+ url:"http://192.168.1.110/mobile/index.php?op=shake&act=bonusex&client_type=ajax",
|
|
|
data:speed_strongs,
|
|
|
dataType:"jsonp",
|
|
|
jsonp:'callback',
|
|
|
success:function(data){
|
|
|
if(data.code !=200) {
|
|
|
- window.removeEventListener('devicemotion', deviceMotionHandler, false);
|
|
|
+ //window.removeEventListener('devicemotion', deviceMotionHandler, false);
|
|
|
return;
|
|
|
}
|
|
|
else {
|
|
|
var shake_New_price=data.datas.mine_bonus.bonus_value;
|
|
|
$('.price span').text(shake_New_price);
|
|
|
- window.removeEventListener('devicemotion', deviceMotionHandler, false);
|
|
|
- setTimeout(function(){
|
|
|
- window.addEventListener('devicemotion', deviceMotionHandler, false);
|
|
|
- },500)
|
|
|
+ // window.removeEventListener('devicemotion', deviceMotionHandler, false);
|
|
|
+ // setTimeout(function(){
|
|
|
+ // window.addEventListener('devicemotion', deviceMotionHandler, false);
|
|
|
+ // },2000)
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
+
|
|
|
+ last_x = x;
|
|
|
+ last_y = y;
|
|
|
+ last_z = z;
|
|
|
}
|
|
|
else {
|
|
|
return false;
|