var eles = Array.prototype.slice.call(document.querySelectorAll(".animated"));
document.addEventListener("scroll", animatedFadeInUp);
animatedFadeInUp();
function animatedFadeInUp() {
eles = eles.filter(function(ele) {
var rect = getRect(ele);
if (rect.isVisible) {
ele.classList.add("slideUp");
return false;
}
return true;
});
if (eles.length <= 0) document.removeEventListener("scroll", animatedFadeInUp);
}
function getRect(ele) {
var inHeight = window.innerHeight;
var rect = ele.getBoundingClientRect();
rect.isVisible = rect.top - inHeight < 0;
// rect.isBottom = rect.bottom - inHeight <= 0;
return rect;
}
if the object does not have a location (position), it will not be affected
, but if it has a location, it will move to a very strange angle first, and then it will change back to its proper position
@keyframes slideUp {
from {
opacity: 0;
-webkit-transform: translate3d(0, 20%, 0);
transform: translate3d(0, 20%, 0);
}
to {
opacity: 1;
-webkit-transform: translate3d(0, 0, 0);
transform: translate3d(0, 0, 0);
}
}
because my actions have transform,
when I locate, I also use transform
like:
position: absolute;
left:15px;
top:50%;
transform: translate(0,-50%);
-webkit-transform: translate(0,-50%);
how to do this: even if you have a location, you can use this action?! And get to the right place?