-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpoof.js
63 lines (58 loc) · 2.08 KB
/
poof.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*!
* Poof! js
* Version 1.0
* https://github.com/iamvanja/poof
*
* Copyright (c) 2013 Vanja Gavric (vanja.gavric.org)
* Dual licensed under the MIT and GPL licenses.
*/
;(function(){
'use strict';
var animatePoof = function(e) {
var isCssAnimCapable = Modernizr.cssanimations,
frameSize = 48,
_getPosition = function(axis){
return parseInt(
e['page'+axis] ||
e.originalEvent.touches[0]['page'+axis], 10
) - (frameSize/2);
},
$poof = $('<div/>', {
'class' : 'poof',
'style' : 'left:'+ _getPosition('X') +'px; top:'+ _getPosition('Y') +'px'
}),
_cssAnimatePoof = function(){
var animEndEventNames = 'webkitAnimationEnd mozAnimationEnd MSAnimationEnd oAnimationEnd animationend';
$poof
.one(animEndEventNames, _animationFinished)
.addClass('animated');
},
_jsAnimatePoof = function() {
var bgPosX = 0,
frame = 0,
frames = 6,
frameDuration = 80,
animateEachFrame = function() {
if (frame < frames){
$poof.css({
backgroundPosition: '0 '+ bgPosX +'px'
});
bgPosX = bgPosX - frameSize;
frame++;
setTimeout(animateEachFrame, frameDuration);
}
};
animateEachFrame();
setTimeout(_animationFinished, frames * frameDuration);
},
_animationFinished = function(){
$poof.remove();
// alert('done');
};
$('body').append($poof);
return (isCssAnimCapable) ? _cssAnimatePoof() : _jsAnimatePoof();
};
$(document).on('click touchstart', function(e){
animatePoof(e);
});
})();