When the text of an element inlinechanges, it usually happens that its calculated widthor heightalso change.
Usually this trivial property is transitionchanged using CSS, for example, adding transitionto change the background-colorelement on hover.
However, the sizes of the elements are inlinereally complex. A simple property transitiondoes 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 inlinechanges, can we change these changes?