forked from ksky521/nodeppt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
2、qrcode页面优化,添加链接之后关闭 3、双屏下一页不能单条显示 4、摇一摇优化
- Loading branch information
Showing
10 changed files
with
173 additions
and
79 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,124 @@ | ||
(function(window, document) { | ||
if (window.DeviceMotionEvent) { | ||
window.addEventListener('devicemotion', deviceMotionHandler, false); | ||
(function (window, document) { | ||
|
||
/** | ||
* from :https://github.com/alexgibson/shake.js/blob/master/shake.js | ||
* | ||
*/ | ||
/** | ||
* 摇一摇实现-抽奖游戏 | ||
* @global | ||
* @class Shake | ||
* | ||
* @example | ||
* ```html | ||
* <script src="../output/template/common/bdbox/game/shake.js"></script> | ||
* <script> | ||
* window.addEventListener('shake', shakeEventDidOccur, false); | ||
* function shakeEventDidOccur () { | ||
* alert('被摇了'); | ||
* } | ||
* </script> | ||
* ``` | ||
*/ | ||
function Shake() { | ||
|
||
//feature detect | ||
this.hasDeviceMotion = 'ondevicemotion' in window; | ||
|
||
//default velocity threshold for shake to register | ||
this.threshold = 15; | ||
|
||
//use date to prevent multiple shakes firing | ||
this.lastTime = new Date(); | ||
|
||
//accelerometer values | ||
this.lastX = null; | ||
this.lastY = null; | ||
this.lastZ = null; | ||
|
||
//create custom event | ||
if (typeof document.CustomEvent === "function") { | ||
this.event = new document.CustomEvent('shake', { | ||
bubbles: true, | ||
cancelable: true | ||
}); | ||
} else if (typeof document.createEvent === "function") { | ||
this.event = document.createEvent('Event'); | ||
this.event.initEvent('shake', true, true); | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
var SHAKE_THRESHOLD = 1500; | ||
var lastUpdate = 0; | ||
var x, y, z, last_x, last_y, last_z; | ||
var shakeEvent = []; | ||
//reset timer values | ||
Shake.prototype.reset = function () { | ||
this.lastTime = new Date(); | ||
this.lastX = null; | ||
this.lastY = null; | ||
this.lastZ = null; | ||
}; | ||
|
||
//start listening for devicemotion | ||
Shake.prototype.start = function () { | ||
this.reset(); | ||
if (this.hasDeviceMotion) { window.addEventListener('devicemotion', this, false); } | ||
}; | ||
|
||
//stop listening for devicemotion | ||
Shake.prototype.stop = function () { | ||
|
||
function deviceMotionHandler(eventData) { | ||
// Grab the acceleration including gravity from the results | ||
var acceleration = eventData.accelerationIncludingGravity; | ||
if (this.hasDeviceMotion) { window.removeEventListener('devicemotion', this, false); } | ||
this.reset(); | ||
}; | ||
|
||
var curTime = +new Date(); | ||
//calculates if shake did occur | ||
Shake.prototype.devicemotion = function (e) { | ||
|
||
if ((curTime - lastUpdate) > 100) { | ||
var current = e.accelerationIncludingGravity, | ||
currentTime, | ||
timeDifference, | ||
deltaX = 0, | ||
deltaY = 0, | ||
deltaZ = 0; | ||
|
||
var diffTime = (curTime - lastUpdate); | ||
lastUpdate = curTime; | ||
if ((this.lastX === null) && (this.lastY === null) && (this.lastZ === null)) { | ||
this.lastX = current.x; | ||
this.lastY = current.y; | ||
this.lastZ = current.z; | ||
return; | ||
} | ||
|
||
deltaX = Math.abs(this.lastX - current.x); | ||
deltaY = Math.abs(this.lastY - current.y); | ||
deltaZ = Math.abs(this.lastZ - current.z); | ||
|
||
x = acceleration.x; | ||
y = acceleration.y; | ||
z = acceleration.z; | ||
if (((deltaX > this.threshold) && (deltaY > this.threshold)) || ((deltaX > this.threshold) && (deltaZ > this.threshold)) || ((deltaY > this.threshold) && (deltaZ > this.threshold))) { | ||
//calculate time in milliseconds since last shake registered | ||
currentTime = new Date(); | ||
timeDifference = currentTime.getTime() - this.lastTime.getTime(); | ||
|
||
var speed = Math.abs(x + y + z - last_x - last_y - last_z) / diffTime * 10000; | ||
if (speed > SHAKE_THRESHOLD) { | ||
shakeEvent.forEach(function(v) { | ||
if (typeof v === 'function') { | ||
v(); | ||
} | ||
}); | ||
if (timeDifference > 1000) { | ||
window.dispatchEvent(this.event); | ||
this.lastTime = new Date(); | ||
} | ||
last_x = x; | ||
last_y = y; | ||
last_z = z; | ||
} | ||
|
||
this.lastX = current.x; | ||
this.lastY = current.y; | ||
this.lastZ = current.z; | ||
|
||
}; | ||
|
||
//event handler | ||
Shake.prototype.handleEvent = function (e) { | ||
|
||
if (typeof (this[e.type]) === 'function') { | ||
return this[e.type](e); | ||
} | ||
}; | ||
|
||
//create a new instance of shake.js. | ||
var myShakeEvent = new Shake(); | ||
myShakeEvent.start(); | ||
|
||
} | ||
window.addShakeEvent = function(fn) { | ||
shakeEvent.push(fn); | ||
} | ||
}(window, document)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.