typing animated text

后端 未结 3 2242
梦谈多话
梦谈多话 2020-12-14 03:55

I have DIV tag with text inside. Is it possible to change the text content in a loop with a typing effect, where it types out, then goes backward deleting the letters and s

3条回答
  •  悲&欢浪女
    2020-12-14 04:16

    Jquery's text() method lets you set the text of an element.

    http://api.jquery.com/text/

    You would be able to use this to animate the contents by calling this in a loop, giving it the contents that you'd like to see in each frame.

    var frames = ['t_', 'ty_', 'typ_', 'type_']

    // loop over frames ... inner part reads frame and prints it
    // use setInterval, etc.
    $('#my-div').text( frames[i] );
    

    I've done more complicated things by splitting the text elements and manipulating the characters but I think in your case it would be overkill.

提交回复
热议问题