【发布时间】:2015-12-11 13:36:01
【问题描述】:
将尝试解释该问题,如果没有意义,请见谅: 我正在尝试在循环时更新对象内的变量。 试图定位类元素的所有父级以在 scrollmagic 插件上使用。 这是我的代码的样子:
var childElement = $('.child');
var myparents = [];
var getParent = function () {
childElement.each(function() {
var theParent = $(this).closest('.parent');
myparents.push(theParent);
});
}();
for (var i=0; i<childElement.length; i++) {
// also using the loop to add animation to every element,
// that's why the loop through other elements
new ScrollMagic.Scene({
// here is where I would need to access each
triggerElement: myparents[i],
triggerHook: 'onEnter'
})
}
元素已成功添加到数组中,并且可以使用它们,但无法在此滚动魔术(对象?)中访问它们。 非常感谢任何提供帮助的人。
【问题讨论】:
-
仅仅因为您调用了一个方法 (ScrollMagic.Scene) 并传入了一个对象 {triggerElement: thing, triggerHook: thing2} 并不意味着这些值一定可以用作您的对象的属性。这将取决于 scrollmagic API。
标签: javascript jquery arrays loops object