-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmorphStyle.js
30 lines (24 loc) · 1.26 KB
/
morphStyle.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
/*
@private
@function morphStyle
@description - picks a random (preset) style to morph, then picks a random value for that style, then animates the element to that style
@param {object} [element] - the element to be morphed
@return {object} - returns the element
@dependencies - GSAP TweenLite, randomize(), objLength()
*/
function morphStyle(element) {
function pickRGB() {
return 'rgb(' + randomize(50, 200, NaN, 'morphStyle 2') + ',' + randomize(50, 200, NaN, 'morphStyle 3') + ',' + randomize(50, 200, NaN, 'morphStyle 4') + ')';
}
var styles = {};
styles[1] = { 'style': 'background', 'value': function () { return pickRGB(); } };
styles[2] = styles[1];
styles[3] = { 'style': 'color', 'value': function () { return pickRGB(); } };
styles[4] = styles[3];
styles[5] = { 'style': 'zoom', 'value': function () { return randomize(1000, 1500, NaN, 'morphStyle 1') / 1000 } };
var number = (function () { return randomize(1, objLength(styles), NaN, 'morphStyle') })();
var stylesObj = {};
stylesObj[styles[number].style] = styles[number].value();;
TweenLite.to(element, 1, stylesObj);
return element;
}