You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
689 B
JavaScript
35 lines
689 B
JavaScript
const transitions = {};
|
|
const eventName = 'transitionend';
|
|
let count = 0;
|
|
|
|
function uniqueId() {
|
|
count += 1;
|
|
return eventName + count;
|
|
}
|
|
|
|
export function cancelTransitionEnd(id) {
|
|
if (transitions[id]) {
|
|
transitions[id].element.removeEventListener(eventName, transitions[id].listener);
|
|
transitions[id] = null;
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
export function onTransitionEnd(element, callback) {
|
|
const id = uniqueId();
|
|
const listener = (evt) => {
|
|
if (evt.currentTarget === evt.target) {
|
|
cancelTransitionEnd(id);
|
|
callback(evt);
|
|
}
|
|
};
|
|
|
|
element.addEventListener(eventName, listener);
|
|
|
|
transitions[id] = { element, listener };
|
|
|
|
return id;
|
|
}
|