Change animations

This commit is contained in:
Tom Raithel
2017-02-15 21:08:48 +01:00
parent cdaa958118
commit c53e6aa5d3
7 changed files with 99 additions and 66 deletions

View File

@@ -18,34 +18,88 @@ const af = (() => {
})();
const animation = (steps) => {
steps.reduce((total, [timeout, step]) => {
steps.map(([timeout, step]) => {
af(() => {
window.setTimeout(step, total + timeout)
window.setTimeout(step, timeout)
});
return total + timeout;
}, 0);
});
}
const createAnimation = (stateA, stateB, delay) => ({
style: stateA,
prepare(target) {
this.style = stateA;
},
run(target) {
af(() => {
window.setTimeout(() => {
this.style = stateB;
}, delay)
});
},
});
const initDetails = (element, fromPjax) => {
if (fromPjax !== true) {
if(!fromPjax) {
return;
}
element.classList.add('animate');
element.classList.add('animate--curtain');
element.classList.add('animate--invisible-content');
element.classList.add('animate--invisible-nav');
animation([
[0, () => {
element.classList.remove('animate--curtain');
}],
[350, () => {
element.classList.remove('animate--invisible-nav');
}],
[150, () => {
element.classList.remove('animate--invisible-content');
}],
])
const items = JSON.parse(element.getAttribute('data-items'));
const details = new Vue({
el: element,
template: element.outerHTML,
data: {
background: createAnimation({
transform: 'translateX(calc((100vw - 1200px) / 2 + 800px))',
}, {
transform: 'translateX(0)',
},
0
),
navHeader: createAnimation({
transform: 'translateY(-20px)',
opacity: '0',
}, {
transform: 'translateY(0px)',
opacity: '1',
},
300
),
text: createAnimation({
transform: 'translateY(-20px)',
opacity: '0',
}, {
transform: 'translateY(0px)',
opacity: '1',
},
600
),
items: items.map((item, i) => (createAnimation({
transform: 'translateY(-40px)',
opacity: '0',
}, {
transform: 'translateY(0px)',
opacity: '1',
},
200 + 100 * i
)))
},
methods: {
createAnimation
},
mounted() {
applyPjax();
this.background.run();
this.navHeader.run();
this.text.run();
this.items.map(item => item.run());
},
updated() {
applyPjax();
},
});
};
export default initDetails;