fellow nerds, I recently stumbled across something rather strange, that essentially breaks the web app I'm working on... Which is that css attributes I add to an HTML element through (vanilla) javascript, seems to be async, to demonstrate that I have a small piece of code...
...
_( leftView ).addClass('notrans');
_( rightView ).addClass('notrans');
if ( fromLeft ) {
if ( !rightFocused ) {
_( leftView ).css({ 'left' : '-100%' })
_( rightView ).css({ 'left' : '-50%' });
} else _( leftView ).css({ 'left' : '-50%' });
}
if ( fromRight ) {
if ( !leftFocused ) {
_( leftView ).css({ 'left' : '100%' });
_( rightView ).css({ 'left' : '150%' });
} else _( rightView ).css({ 'left' : '100%' });
}
_( leftView ).removeClass('notrans');
_( rightView ).removeClass('notrans');
...
NOTE: The small underscore you see everywhere, is a small library I made and tested... And I'm 99% sure that the CSS, add class and remove class functions work.
Now, the problem is that when I get to the remove class part of the code ( last two lines ), the CSS doesn't seem to have been applied yet. So when it finally does, I will already have removed the notrans class, and the elements will move with a transition instead of none. This can be fixed with a 1ms timeout to the removal of the classes but will break some other stuff down the line... So is there anybody that knows if adding CSS attributes through JS is async, and how to fix it?:)
Aske K.