CSS/JS: Animate Inline Element Upon Text Change

前端 未结 3 1624
再見小時候
再見小時候 2021-01-06 03:15

When an inline element\'s text changes, it is usually the case that its computed width or height changes as well.

Usually it\'

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-06 04:16

    You could try a little bit of jQuery animation:

    function changeText(el) {
        el.animate(
        {
            opacity: 0
        }, 
        {
            duration: 'slow', 
            complete: function () {
                $(this).text('New Text');
                $(this).animate({opacity: 1}, 'slow');
            }
        });  
    }
    

    Here is a fiddle.

提交回复
热议问题