Answer the question
In order to leave comments, you need to log in
Why doesn't transitionend fire and what exactly happens when changing in the DOM tree?
There is a very trivial code that works as expected:
<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<style type="text/css">
.opacity {
opacity: 0;
}
</style>
</head>
<body>
<div>1</div>
<div>2</div>
<div>3</div>
<div id="move" style="transition-duration: 1s;">4</div>
<script>
$(document).ready(function() {
function on_transitionend(event) {
$(this).toggleClass('opacity');
}
$('div').on('transitionend webkitTransitionEnd oTransitionEnd', on_transitionend);
$('#move').toggleClass('opacity');
});
</script>
</body>
</html>
function on_transitionend(event) {
$(this).insertBefore($('div').get(0));
$(this).toggleClass('opacity');
}
function on_transitionend(event) {
$(this).insertBefore($('div').get(0));
var el = this
setTimeout(function() {$(el).toggleClass('opacity');}, 0);
}
Answer the question
In order to leave comments, you need to log in
Hypothesis: when changing the DOM of the tree, an API event is fired, which is placed in the event queue with the highest priority. Accordingly, after the completion of the main thread, it fires and produces a kind of "remapping" of the entire DOM tree, including handlers and properties.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question