This is currently happening in chrome, in firefox I did not have this problem (yet).
Here is a VERY simplified version of my problem.
HTML:
<div class="thumbnail"> <a href='#' id="clickMe">Click me!</a> </div>
CSS
div { width: 200px; height: 300px; background-color: purple; } a { position: absolute; } @media (max-width: 991px) { div { height: 200px; } }
JavaScript:
$(document).ready(function () { var $parent = $('#clickMe').parent(); function resize() { $('#clickMe').offset({ top: $parent.offset().top + $parent.height()-$('#clickMe').height() }); } $(window).on('resize', resize); resize(); });
Problem:
So what does it give when I resize (without drag and drop)? Well, javascript starts first and sets the position to <a></a> , then CSS applies a change in height if we are <992 px.
Logically, the button is now visually located outside the div, and not on the border, as I originally defined it.
Workaround proposed in this post.
jQuery - how to wait for the "end" of the "resize" event and only then perform an action?
var doit; $(window).on('resize', function(){ clearTimeout(doit); doit = setTimeout(resize, 500); });
Workaround is not what I'm looking for:
However, in my situation, I really don’t only need to call “resize” when resizing is actually done. I just want my javascript to start after css has finished loading / or finished with this change. And it's just really slow, using this function to “randomly” run JS when css can be completed.
Question:
Is there a solution? Does anyone know of a method in js to wait for css to fully make changes while resizing?
Additional Information:
Testing this with jsfiddle will most likely not give you the same result as I. My css file has many lines and I use Twitter Bootstrap. These two take up a lot of resources, slowing down the css application (I think, tell me if I am wrong).
Miljan Puzović - proposed a solution by uploading css files via js, and then applied js changes when the js event on css ends.