码迷,mamicode.com
首页 > 移动开发 > 详细

手机摇一摇进入某页面_js代码

时间:2017-05-07 18:42:20      阅读:1099      评论:0      收藏:0      [点我收藏+]

标签:z-index   one   cti   top   ati   摇一摇   fft   javascrip   asc   

// 摇一摇
 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代码

标签:z-index   one   cti   top   ati   摇一摇   fft   javascrip   asc   

原文地址:http://www.cnblogs.com/zuosong160522/p/6821351.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!