如何在网页上的javascript中接收视差事件,当它被送达到iPhone时?我查看了github.com的404页面,它正在响应使用加速度计的动作。只需尝试访问github.com/f7fu3f73fh39f8h3f93fh398h (或任何合成页面),并查看他们正在制作的酷酷视差动画。
我看了一下源代码,没能看到他们为获取这些事件所做的任何特殊的事情。
发布于 2014-06-06 01:26:08
我想他们只是在使用柏拉图
从柏拉图的示例页看来,加速度计的东西是由那个插件来处理的。
它们只在页面中包含jquery和plax。
<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
// 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
};
}https://stackoverflow.com/questions/23958909
复制相似问题