【发布时间】:2013-10-25 05:21:23
【问题描述】:
我的 jquery 技能不是很好。我通常做的是使用插件,然后最终弄清楚我需要做什么。
我现在正在做的是我有一个幻灯片脚本,我想要它,以便在下一张幻灯片变为活动/可见时,运行一个函数。该函数所做的是检查任何具有 css 类型(在数组中设置的类型)的 ID,然后向其添加一个类。我这样做的原因是因为它需要根据类型扩展做不同的事情。
我有一些通用代码,但我真的不知道自己在做什么。到目前为止,这是我所拥有的:
功能:
function doAnimate(index) {
var item = $animations[index];
for (var i = 0; i < item.length; i++) {
var obj = item[i];
if (obj['type'] = "css") {$(this).addClass('in');}
};
}
数组:
var $animations = [
[{
ID: "s5-01",
type: "css"
}],
[{
ID: "s5-02",
type: "css"
}],
[{
ID: "s5-03",
type: "css"
}],
[{
ID: "s5-04",
type: "css"
}],
[{
ID: "#5-05",
type: "css"
}]
];
这是幻灯片脚本,它应该在哪里运行:
carousel.owlCarousel({
... cut stuff out that isn't important
pagination:true,
afterMove: function(elem) {
doAnimate();
}
});
这是在 HTML 中如何设置这个特定的
<div class="slide" id="slide-05">
<img id="s5-01" src="img1.png" />
<img id="s5-02" src="img2.png" />
<img id="s5-03" src="img3.png" />
<img id="s5-04" src="img4.png" />
<img id="s5-05" src="img5.png" />
</div>
所以我就是这样,浏览器控制台显示:Uncaught TypeError: Cannot read property 'length' of undefined
我基本上有点迷茫,需要一些帮助才能完成这项工作。我确定这是一些我看不到的基本内容,或者我设置的全部错误。
任何建议将不胜感激!
【问题讨论】:
标签: javascript jquery html arrays function