When the text of an element inline
changes, it usually happens that its calculated width
or height
also change.
Usually this trivial property is transition
changed using CSS, for example, adding transition
to change the background-color
element on hover.
However, the sizes of the elements are inline
really complex. A simple property transition
does not animate changes in the computed width
.
See an example by clicking here: https://jsfiddle.net/mz103/59s42ys4/ or by viewing it below:
$("div").on("click", function() {
$(this).text("Although my width changes, it is not aniamted.");
});
div {
display: inline-block;
background-color: red;
padding: 8px 16px;
transition: width 0.3s; // Notice, this doesn't transition the width upon change.
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>Click me.</div>
Run codeHow if the text of an element inline
changes, can we change these changes?