2012-08-31 2 views
1
내가 (문자열 photo 또는 bio 수를 ether 것) 모드를 평가하고 파이어 폭스 animationend 또는 여부에 따라 이벤트 리스너를 추가 할 객체를 만들기 위해 노력하고
({ 
photo: foo.addEventListener("animationend", photoCycle, true) || foo.addEventListener("webkitAnimationEnd", photoCycle, true), 

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

크롬 webkitanimationend. 이상하게도, 모드가 photo 인 경우 bio 키의 유효하지 않은 레이블에 대한 구문 오류가 발생합니다.잘못된 라벨 이벤트 리스너를 추가 할 Javascript-

답변

1

이 구문은 이름이 지정되지 않은 개체 속성에 값을 할당합니다. 또한 addEventListener가 두 브라우저 모두에서 유효한 함수이기 때문에 올바른 이벤트 이름을 선택하는 메서드 또는 메서드가 작동하지 않습니다.

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

foo.addEventListener(eventName, bioCycle, true) 
: 여기

는이 작업을 수행하는 몇 가지 코드
관련 문제