forked from matthewmueller/unmatrix
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.html
More file actions
63 lines (56 loc) · 1.37 KB
/
test.html
File metadata and controls
63 lines (56 loc) · 1.37 KB
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
<html>
<head>
<title>transform component</title>
<style>
#box {
width: 100px;
height: 100px;
background: blue;
-webkit-transform: scale(2) translate(200px, 100px) rotate(60deg) skew(20deg);
position: absolute;
}
#box2 {
width: 100px;
height: 100px;
background: red;
position: absolute;
opacity: 0.7;
}
</style>
</head>
<body>
<h1>unmatrix component</h1>
<div id="box"></div>
<div id="box2"></div>
<script src="build/build.js" type="text/javascript"></script>
<script type="text/javascript">
var unmatrix = require('unmatrix');
var t = unmatrix(box);
console.log(JSON.stringify(t, true, 2));
box2.style.webkitTransform = toString(t);
t = unmatrix('scale(2) translate(200px, 100px) rotate(60deg) skew(20deg)');
console.log(JSON.stringify(t, true, 2));
function toString(props) {
var out = [];
function wrap(k, v) {
return k + '(' + v + ')';
}
for(var k in props) {
switch(k) {
case 'translateX':
case 'translateY':
out.push(wrap(k, props[k] + 'px'));
break;
case 'rotate':
case 'skew':
out.push(wrap(k, props[k] + 'deg'));
break;
default:
out.push(wrap(k, props[k]));
}
}
return out.join(' ');
};
</script>
</body>
</html>