width/height
top/right/bottom/left
padding
font-size
color
background
box-shadow
border-radius
opacity
scale
rotate
translate
var opacity = 0;
// runs every 16ms to try to achieve 60fps (1000ms/60 ~= 16ms).
var fadeIn = setInterval(function() {
if(opacity < 1) {
element.style.opacity = (opacity += 0.05);
} else {
clearInterval(fadeIn)
}
}, 16);
// requestAnimationFrame: Attempts to run at 60fps based on
// whether the browser is in an optimal state.
var opacity = 0;
var fadeIn = function() {
if(opacity < 1){
window.requestAnimationFrame(fadeIn);
element.style.opacity = (opacity += 0.05);
}
}
fadeIn();
var h1 = element1.clientHeight; // Read (measures the element)
element1.style.height = (h1 * 2) + 'px'; // Write (invalidates current layout)
var h2 = element2.clientHeight; // Read (measure again, so must trigger layout)
element2.style.height = (h1 * 2) + 'px'; // Write (invalidates current layout)
var h3 = element3.clientHeight; // Read (measure again, so must trigger layout)
element3.style.height = (h3 * 2) + 'px'; // Write (invalidates current layout)
// Readenzie
var h1 = element1.clientHeight;
var h2 = element2.clientHeight;
var h3 = element3.clientHeight;
// Writenzie
element1.style.height = (h1 * 2) + 'px';
element2.style.height = (h1 * 2) + 'px';
element3.style.height = (h3 * 2) + 'px';
var debounce = function(func, wait, immediate) {
var timeout, result;
return function() {
var context = this, args = arguments;
var later = function() {
timeout = null;
if (!immediate) result = func.apply(context, args);
};
var callNow = immediate && !timeout;
clearTimeout(timeout);
timeout = setTimeout(later, wait);
if (callNow) result = func.apply(context, args);
return result;
};
};
window.addEventListener('scroll', function(){
debounce(function(){
//cool animation
},100)
},false)
.logo {
animation: myAnimation 2s linear forwards;
}
@keyframes myAnimation {
0% {
opacity: 0;
transform: scale(0, 0);
}
25% {
opacity: 1;
transform: scale(1, 1);
}
50% {
transform: translate(0px, 0);
}
100% {
transform: translate(100px, 0);
}
}
So what happens when somebody wants the translate to take an extra 400ms?
.logo {
animation: myAnimation 2s linear forwards;
}
@keyframes myAnimation {
0% {
opacity: 0;
transform: scale(0, 0);
}
25% {
opacity: 1;
transform: scale(1, 1);
}
50% {
transform: translate(0px, 0);
}
100% {
transform: translate(100px, 0);
}
}
var el = document.getElementsByClassName('logo')
Velocity(el, {
opacity: [1, 0],
scale:[1, 0]
},{
duration:500,
easing: "linear"
}
);
Velocity(el, {
translateY: '100px'
},{
duration:1000,
delay:500,
easing: "linear"
}
);
var el = document.getElementsByClassName('logo')
TweenLite.fromTo(el, .5, {
opacity:0,
scale:0,
ease:"Linear.easeNone"
},{
opacity:1,
scale:1,
ease:"Linear.easeNone",
onComplete: function(){
TweenLite.to(el, 1, {
delay:.5,
y:100,
ease:"Linear.easeNone"
});
}
}
);