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 starting all over with a new text? Is this possible with jquery?
相关问题
- How to fix IE ClearType + jQuery opacity problem i
- jQuery add and remove delay
- Include empty value fields in jQuery .serialize()
- React Native Inline style for multiple Text in sin
- Disable Browser onUnload on certain links?
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_']
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.
Typing Effect + Erasing Effect + Blinking Cursor
I modified Simon Shahriveri codepan to further add the blinking effect of the cursor. It's compatible with IE also.
Here's the end result: https://codepen.io/jerrygoyal/pen/vRPpGO
HTML:
CSS:
JS:
Just a simple approach:
So basically jQuery gets the
data-text
of your element, inserts character by character, and the pulsating "caret" is nothing by a CSS3 animated:after
element of that SPAN.See also: Generate random number between two numbers in JavaScript