I have very basic promise based self-calling function that:
- takes collection of divs with certain class
- checks whether they have just been moved left or right
- based on result makes choice to move (
transform: translate
) them withclassList.add()
/classList.remove()
- and on
transitionend
- calls itself
here is function:
function transitionTest(){
console.log('called --- transitionTest() ');
var dummies = document.getElementsByClassName('dummy'),
count = dummies.length;
if(window.cache==='right'){
var transitionCollection=0;
for(var i = 0; i < dummies.length; i++){
dummies[i].classList.remove('right');
dummies[i].addEventListener('transitionend', function(){
transitionCollection++;
if( transitionCollection === dummies.length ){
transitionTest();
}
});
}
window.cache='';
} else {
var transitionCollection=0;
for(var i = 0; i < dummies.length; i++){
dummies[i].classList.add('right');
dummies[i].addEventListener('transitionend', function(){
transitionCollection++;
if( transitionCollection === dummies.length ){
transitionTest();
}
});
}
window.cache='right';
}
and here is working fiddle
So, what is wrong?
- Nothing, if you are accessing via modern browser but not latest versions of Chrome on Windows
- Nothing, if you are accessing via latest versions of Chrome on Windows but refrain from causing any mouse events such as mouseenter/leave, click, even window
focus
event (e.g. if you stand still) - If you do such, infinite left - right movement of dummy div will occasionally break, under unclear circumstances
What gets wrong:
Dummy div
, which is moving left-right infinitely, on mouseenter
, mouseleave
, click
, sometimes and sometimes not (exact conditions are unclear) will:
- go to end CSS value without transition and resumes normal operation after a while
- stop entirely and resumes normal operation after a while
- slow down (!? yeah, I wish I was kidding ) and stop/go to end CSS value
These errors are occurring in Chrome 45 (Win 7) and, less intensively Chrome 42 (Win XP) - which are platforms that I was able to test by now. Just to note, upper code does not need to be cross browser, I'm fully aware of implications.