首页 > 代码库 > 手机摇一摇进入某页面_js代码
手机摇一摇进入某页面_js代码
// 摇一摇 var SHAKE_THRESHOLD = 1600; var last_update = 0; var x = y = z = last_x = last_y = last_z = 0; if (window.DeviceMotionEvent) { window.addEventListener(‘devicemotion‘, deviceMotionHandler, false); } else { alert(‘本设备不支持摇一摇事件‘); } function deviceMotionHandler(eventData) { var acceleration = eventData.accelerationIncludingGravity; var curTime = new Date().getTime(); if ((curTime - last_update) > 100) { var diffTime = curTime - last_update; last_update = curTime; x = acceleration.x; y = acceleration.y; z = acceleration.z; var speed = Math.abs(x + y + z - last_x - last_y - last_z) / diffTime * 10000; var status = document.getElementById("status"); if (speed > SHAKE_THRESHOLD) { openswt(); } last_x = x; last_y = y; last_z = z; } } // function doResult() { // window.location.href = "http://www.mamicode.com/tel:";} function openswt() {window.location.href = "http://www.mamicode.com/call.html";} document.write(‘<div style="position:fixed;top:2%;right:0px;width:55px;z-index:10000;"><a href="javascript:getSwt(\‘yao\‘);"><img src="http://www.baidu.com/images/yao.gif" width="55" border="0"></a></div>‘);
手机摇一摇进入某页面_js代码
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。