それぞれ (ある程度の) 持続時間でアニメーション化する複数の要素があります。jQuery ライブラリとDavid Walshtransitionend
のヘルパー関数を使用して、CSS3 トランジションを使用してアニメーション化しています。
私の問題は、transitionEnd
イベントが発生していないことです! (Chrome & Firefox)
私のコード:
var $children = $container.find('.slideblock').children();
if(Modernizr.csstransitions && Modernizr.csstransforms3d) {
if($.browser.webkit === true) {
$children.css('-webkit-transform-style','preserve-3d')
}
$children.each(function(i){
$(this).on(whichTransitionEvent,function () {
$(this).remove();
});
$(this).show().css('animation','slideOutToRight ' + ((Math.random() / 2) + .5) + 's');
});
}
アップデート
変数はwhichTransitionEvent
、イベント名を含む文字列を返す自己実行関数を指します。
var whichTransitionEvent = (function (){
var t;
var el = document.createElement('fakeelement');
var transitions = {
'transition' :'transitionEnd',
'OTransition' :'oTransitionEnd',
'MSTransition' :'msTransitionEnd',
'MozTransition' :'transitionend',
'WebkitTransition' :'webkitTransitionEnd'
}
for(t in transitions){
if( el.style[t] !== undefined ){
return transitions[t];
}
}
} ());
console.log(whichTransitionEvent); // returns "webkitTransitionEvent" in Chrome
console.log(typeof whichTransitionEvent); // returns "string"