var pointsArray = document.getElementsByClassName('point');
var animatePoints = function(points) {
var revealPoint = function(index) {
points[index].style.opacity = 1;
points[index].style.transform = "scaleX(1) translateY(0)";
points[index].style.msTransform = "scaleX(1) translateY(0)";
points[index].style.WebkitTransform = "scaleX(1) translateY(0)";
}
}
for (i = 0; i < pointsArray.length; i++)
{
revealPoint(i);
}
window.onload = function() {
var sellingPoints = document.getElementsByClassName("selling-points")[0];
var scrollDistance = sellingPoints.getBoundingClientRect().top - window.innerHeight + 200;
window.addEventListener("scroll", function(event) {
if (document.documentElement.scrollTop || document.body.scrollTop >= scrollDistance)
{
animatePoints(pointsArray);
}
});
}
控制台显示在定义时,revealPoint未定义。
答案 0 :(得分:0)
在animatePoints的函数范围中定义的revealPoint,而不是在它被调用的for循环中。
答案 1 :(得分:0)
哪个执行上下文未定义? revealPoint似乎只在animatePoints的上下文中定义。它只能从该函数中访问,并且不会从那里返回。
答案 2 :(得分:0)
var animatePoints = function(points){
var revealPoint = function(index){
points[index].style.opacity = 1;
points[index].style.transform = "scaleX(1) translateY(0)";
points[index].style.msTransform = "scaleX(1) translateY(0)";
points[index].style.WebkitTransform = "scaleX(1) translateY(0)";
}
for (i = 0; i < points.length; i++)
{
revealPoint(i);
}
};