Это потому, что Chrome все еще не поддерживает FF 45 и не поддерживает обработчик HTMLElement.onanimationend
.
Я не могу сказать для Firefox 45 (что вам следует обновить btw), ноChrome поддерживает GlobalEventHandler's (window
), что объясняет, почему обработчики, подключенные через EventTarget.addEventListener
, его поймают.
window.onanimationend = e => {
// stacksnippet's console also has CSS animations...
if(e.animationName === 'roundify')
console.log({ // logging the full event will kill the page
target: e.target,
type: e.type,
animationName: e.animationName
});
}
#anim {
width: 100px;
height: 100px;
background: #333;
animation: roundify 2s forwards;
}
@keyframes roundify {
100% { border-radius: 50%; }
}
<div id="anim"></div>
Теперь, если вам действительно нужны обработчики HTMLElement и Document, вы можете очень хорошо реализовать их самостоятельно, но учтите, что вообще плохая идея изменитьтакие прототипы DOM.
// now we only have our Element's event
anim.onanimationend = e => console.log({ // logging the full event will kill the page
target: e.target,
type: e.type,
animationName: e.animationName
});
#anim{
width: 100px;
height: 100px;
background: #333;
animation: roundify 2s forwards;
}
@keyframes roundify {
100% { border-radius: 50%; }
}
<script>
// This does modify both HTMLElement and Document protoypes,
// should be placed at top most position in the doc possible
(function(){
if(
!("onanimationend" in HTMLElement.prototype) &&
window.onanimationend !== undefined
) {
// will attach the handler on a the Object's `__animationendhandler` property
const getsetanimationend = {
get: function() {
return this._animationendhandler || null
},
set: function(func) {
this.removeEventListener('animationend', this._animationendhandler);
if(typeof func !== 'function') {
this._animationendhandler = null;
return;
}
this._animationendhandler = func;
this.addEventListener('animationend', func);
}
};
Object.defineProperty(HTMLElement.prototype, 'onanimationend', getsetanimationend);
Object.defineProperty(Document.prototype, 'onanimationend', getsetanimationend);
}
})();
</script>
<div id="anim"></div>