forked from ryanflorence/CSSAnimation
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
87d1eb4
commit b24e005
Showing
3 changed files
with
147 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
--- | ||
name: Transform.js | ||
license: MIT-style license. | ||
authors: Ryan Florence <http://ryanflorence.com> | ||
provides: [Transform] | ||
... | ||
*/ | ||
|
||
var Transform = function(element, style){ | ||
this.element = element; | ||
this.style = style; | ||
}; Transform.prototype = { | ||
|
||
set: function(def){ | ||
this.element.style[this.style] = def; | ||
return this; | ||
}, | ||
|
||
clear: function(){ | ||
return this.set(''); | ||
}, | ||
|
||
regexes: { | ||
'rotateX': /rotateX\((-?[0-9]+deg)\)/, | ||
'rotateY': /rotateY\((-?[0-9]+deg)\)/, | ||
'rotateZ': /rotateZ\((-?[0-9]+deg)\)/, | ||
'translateX': /translateX\((-?[0-9]+%)\)/, | ||
'translateY': /translateY\((-?[0-9]+%)\)/, | ||
'translateZ': /translateZ\((-?[0-9]+px)\)/ | ||
}, | ||
|
||
add: function(rule, value){ | ||
var transform = this.element.style[this.style], | ||
match = new RegExp(this.regexes[rule]).test(transform); | ||
unit = new RegExp(/rotate/).test(rule) | ||
? 'deg' | ||
: new RegExp(/translateZ/).test(rule) | ||
? 'px' | ||
: '%', | ||
shared = rule + '(' + value + unit +')'; | ||
|
||
if (transform == 'none') transform = ''; | ||
return match | ||
? this.set(transform.replace(this.regexes[rule], shared)) | ||
: this.set(transform + ' ' + shared); | ||
}, | ||
|
||
translate: function(axis, value){ | ||
if (typeof axis === 'string') return this.add('translate' + axis.toUpperCase(), value); | ||
for (i in axis) if (axis.hasOwnProperty(i)) this.translate(i, axis[i]) | ||
return this; | ||
}, | ||
|
||
rotate: function(axis, value){ | ||
if (typeof axis === 'string') return this.add('rotate' + axis.toUpperCase(), value); | ||
for (i in axis) if (axis.hasOwnProperty(i)) this.rotate(i, axis[i]) | ||
return this; | ||
} | ||
|
||
}; |
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,71 @@ | ||
<style> | ||
#container { | ||
width: 400px; | ||
height: 280px; | ||
position: absolute; | ||
left: 440px; | ||
top: 40px; | ||
text-align: center; | ||
-webkit-perspective: 800; | ||
} | ||
#transformer { | ||
-webkit-transition: -webkit-transform 500ms ease-out; | ||
width: 50%; | ||
height: 50%; | ||
background: #ccc; | ||
line-height: 100px; | ||
font-size: 25px; | ||
} | ||
</style> | ||
|
||
<div id=container> | ||
<div id=transformer>Transform me!</div> | ||
</div> | ||
|
||
<script src="/depender/build?require=Transform/Transform,Core/Element.Event"></script> | ||
|
||
<script> | ||
var transform = new Transform(document.getElementById('transformer'), 'WebkitTransform'); | ||
|
||
makeActions([ | ||
{ | ||
fn: function(){ | ||
transform.set('translateX(50%)'); | ||
}, | ||
title: "set('translateX(50%)')" | ||
}, | ||
{ | ||
fn: function(){ | ||
transform.translate('y', 50); | ||
}, | ||
title: "transform.translate('y', 50)" | ||
}, | ||
{ | ||
fn: function(){ | ||
transform.rotate({x: 30, y: 30}); | ||
}, | ||
title: "transform.rotate({x: 30, y: 30})" | ||
}, | ||
{ | ||
fn: function(){ | ||
transform.translate('z', -100); | ||
}, | ||
title: "transform.translate('z', -100)" | ||
}, | ||
{ | ||
fn: function(){ | ||
transform.translate('Z', 0); | ||
}, | ||
title: "transform.translate('Z', 0)", | ||
description: 'The last action defined translateZ, this action should just replace it, leaving the others in tact.' | ||
}, | ||
{ | ||
fn: function(){ | ||
transform.clear(); | ||
}, | ||
title: 'clear' | ||
} | ||
]); | ||
|
||
|
||
</script> |
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,10 @@ | ||
name: Transform | ||
|
||
author: Ryan Florence | ||
|
||
copyright: "© [Ryan Florence](http://ryanflorence.com)" | ||
|
||
license: MIT-style license. | ||
|
||
sources: | ||
- "Source/Transform.js" |