首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >视差:在网页中获取视差事件

问视差:在网页中获取视差事件
EN

Stack Overflow用户
提问于 2014-05-30 16:08:59
回答 1查看 172关注 0票数 1

如何在网页上的javascript中接收视差事件,当它被送达到iPhone时?我查看了github.com的404页面,它正在响应使用加速度计的动作。只需尝试访问github.com/f7fu3f73fh39f8h3f93fh398h (或任何合成页面),并查看他们正在制作的酷酷视差动画。

我看了一下源代码,没能看到他们为获取这些事件所做的任何特殊的事情。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-06-06 01:26:08

我想他们只是在使用柏拉图

从柏拉图的示例页看来,加速度计的东西是由那个插件来处理的。

它们只在页面中包含jquery和plax。

代码语言:javascript
复制
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
<script type="text/javascript" src="js/plax.js"></script>
<script type="text/javascript">
  $(document).ready(function () {
    $('#plax-sphere-1').plaxify({"xRange":40,"yRange":40})
    $('#plax-logo').plaxify({"xRange":20,"yRange":20})
    $('#plax-sphere-2').plaxify({"xRange":10,"yRange":10})
    $('#plax-sphere-3').plaxify({"xRange":40,"yRange":40,"invert":true})
    $.plax.enable()
  })
</script>

然后在plax.js lines 209-243

代码语言:javascript
复制
// Determine if the device has an accelerometer
//
// returns true if the browser has window.DeviceMotionEvent (mobile)
function moveable(){
  return (ignoreMoveable===true) ? false : window.DeviceOrientationEvent !== undefined;
}

// The values pulled from the gyroscope of a motion device.
//
// Returns an object literal with x and y as options.
function valuesFromMotion(e) {
  x = e.gamma;
  y = e.beta;

  // Swap x and y in Landscape orientation
  if (Math.abs(window.orientation) === 90) {
    var a = x;
    x = y;
    y = a;
  }

  // Invert x and y in upsidedown orientations
  if (window.orientation < 0) {
    x = -x;
    y = -y;
  }

  motionStartX = (motionStartX === null) ? x : motionStartX;
  motionStartY = (motionStartY === null) ? y : motionStartY;

  return {
    x: x - motionStartX,
    y: y - motionStartY
  };
}
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23958909

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档