Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
g-shake: configurable shake animation
- Loading branch information
Yvonne Yip
committed
Apr 25, 2013
1 parent
66474fe
commit 9344922
Showing
3 changed files
with
102 additions
and
1 deletion.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<link rel="import" href="g-animation.html"> | ||
<element name="g-shake" extends="g-animation" on-click="clickHandler"> | ||
<script> | ||
Toolkit.register(this, { | ||
publish: { | ||
targetId: '', | ||
duration: 0.3, | ||
magnitude: '10px', | ||
period: 0.1, | ||
easing: 'ease-in', | ||
autoplay: true | ||
}, | ||
ready: function() { | ||
this.super(); | ||
this.magnitudeChanged(); | ||
this.periodChanged(); | ||
}, | ||
durationChanged: function() { | ||
this.super(); | ||
this.generateProperties(); | ||
}, | ||
magnitudeChanged: function() { | ||
this.generateProperties(); | ||
}, | ||
periodChanged: function() { | ||
this.generateProperties(); | ||
}, | ||
generateProperties: function() { | ||
var transforms = ['translateX(0px)']; | ||
if (this.magnitude) { | ||
for (var i = 0; i < this.duration / this.period; i++) { | ||
transforms.push('translateX(-' + this.magnitude + ')'); | ||
transforms.push('translateX(' + this.magnitude + ')'); | ||
} | ||
transforms.push('translateX(-' + this.magnitude + ')'); | ||
transforms.push('translateX(0px)'); | ||
} | ||
this.properties = { | ||
transform: transforms | ||
}; | ||
}, | ||
clickHandler: function() { | ||
// for demo | ||
this.play(); | ||
} | ||
}); | ||
</script> | ||
</element> |
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Animation Components</title> | ||
<link rel="import" href="../../components/animation/g-bounce.html"> | ||
<link rel="import" href="../../components/animation/g-shake.html"> | ||
<script src="../../toolkit.js"></script> | ||
<style> | ||
body { | ||
text-align: center; | ||
} | ||
div#target { | ||
display: inline-block; | ||
background-color: #cccccc; | ||
border-radius: 5px; | ||
padding: 5px 10px; | ||
margin: 100px; | ||
color: white; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div id="target">shake</div> | ||
<g-bounce id="bounce" duration="1"></g-bounce> | ||
<g-shake id="shake"></g-shake> | ||
<script> | ||
document.addEventListener('WebComponentsReady', function() { | ||
shake.target = target; | ||
shake.play(); | ||
}); | ||
</script> | ||
</body> | ||
</html> |