Skip to content

Instantly share code, notes, and snippets.

@joeylin
Last active August 29, 2015 14:05
Show Gist options
  • Save joeylin/57ff24cfbf36665f915d to your computer and use it in GitHub Desktop.
Save joeylin/57ff24cfbf36665f915d to your computer and use it in GitHub Desktop.
正确取得transitionend事件的可用名字
function getTransitionEndEventName() {
var obj = {
TransitionEvent: "transitionend",
WebKitTransitionEvent: "webkittransitionEnd",
OTransitionEvent: "OTransitionEnd",
otransitionEvent: "otransitionEnd",
MSTransitionEvent: "MSTransitionEnd"
}
// var ev = document.createEvent("TransitionEvent"); // FIXME: un-specified
// ev.initTransitionEvent("transitionend", true, true, "some-unknown-prop", -4.75);
// document.body.dispatchEvent(ev);
var ret = false, ev
for (var name in obj) {
try {
ev = document.createEvent(name)//只有firefox不支持
ret = obj[name]
break
} catch (e) {
}
}
if (ret === false) {
//https://bugzilla.mozilla.org/show_bug.cgi?id=868751
//https://hg.mozilla.org/integration/mozilla-inbound/rev/a20ea0d494a0
try {
ev = new TransitionEvent("transitionend",
{
bubbles: true,
cancelable: true,
propertyName: "some-unknown-prop",
elapsedTime: 0.5,
pseudoElement: "pseudo"
});
ret = "transitionend"
} catch (e) {
}
}
getTransitionEndEventName = function() {
return ret
}
return ret
}
console.log(getTransitionEndEventName() + "!!!!!!!!!!!!!!!!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment