手机摇一摇进入某页面_js代码
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了手机摇一摇进入某页面_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 = "tel:";} function openswt() {window.location.href = "/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代码的主要内容,如果未能解决你的问题,请参考以下文章