1
({
photo:  foo.addEventListener("animationend", photoCycle, true) ||  foo.addEventListener("webkitAnimationEnd", photoCycle, true),

bio: foo.addEventListener("animationend", bioCycle, true) ||  foo.addEventListener("webkitAnimationEnd", bioCycle, true)
})[mode]

我正在尝试创建一个对象来评估模式(它将是字符串photobio)并根据它是 firefoxanimationend还是 chrome添加事件侦听器webkitanimationend。奇怪的是,当模式是photo我得到bio键的无效标签的语法错误。

4

1 回答 1

1

此构造正在为未命名的对象属性赋值。此外,选择正确事件名称的 or 方法也不起作用,因为 addEventListener 在两个浏览器上都是有效的函数。

这是一些执行此操作的代码:

var fn = (mode == "photo") ? photoCycle : bioCycle;
var eventName = ((navigator.userAgent.indexOf("WebKit") != -1) ? "webkitAnimationEnd" : "animationEnd";

foo.addEventListener(eventName, bioCycle, true)
于 2012-08-31T03:28:02.887 回答