♥摇一摇手机,换个背景色吧

2014-04-22 15:50:41 -0400
♥摇一摇手机,换个背景色吧
<script type="text/JavaScript">
var color = new Array('#f5f5f5', '#9D9D9D', 'pink', '#FFA042', '#B766AD', '#00A600'); 
//随机变化的颜色代码
if(window.DeviceMotionEvent) { 
    var speed = 12;
    var x = y = z = lastX = lastY = lastZ = 0;
    window.addEventListener('devicemotion', function(){  
    var acceleration =event.accelerationIncludingGravity;  
      x = acceleration.x;  
      y = acceleration.y;  
      if(Math.abs(x-lastX) > speed || Math.abs(y-lastY) > speed) {  
      document.getElementById('whole_body').style.backgroundColor = color[Math.round(Math.random()*10)%6];
//指定位置的背景色
      }  
      lastX = x;  
      lastY = y;  
    }, false); 

</script>
<span style="color:green;border-bottom:1px dashed grey;">♥摇一摇手机,换个背景色吧</span>

«Newer      Older»
Comment:
Name:

Back to home

Subscribe | Register | Login | N