Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change text (html) with .animate

I am trying to animate the html part of a tag ( <font id="test" size="7">This Text!</font> ) using jQuery's Animate function, like so:

$("#test").delay(1500).animate({text:'The text has now changed!'},500); 

However nothing happens, it does not change the text.

How can I do this? Thanks!

like image 805
Jeff Avatar asked Jun 10 '11 11:06

Jeff


People also ask

How do you automatically change text in HTML?

setInterval(function () { $('#role'). html(roles[roleId]); roleId = roleId + 1; if(roleId >= roles. length) { roleId = 0; } }, 1000); });

Can you animate text in HTML?

CSS allows animation of HTML elements without using JavaScript or Flash! In this chapter you will learn about the following properties: @keyframes.

Can you animate text in CSS?

Things such as scrolling text, shadows, text glow, style, colour, 3D effect and many more. On this article we'll be focusing on CSS Text Animations. These are simple and easy to integrate into your design, with pure HTML, CSS and (in some of them) some JavaScript. You can use them on scrolling animation websites.

How do you add text transitions in CSS?

CSS Code: Step 1: Do some basic style like background-color, text-color, margins, padding etc. Step 2: Now, use before select/or to set the content of span to an initial word. Step 3: Use animation property to set the total time for the animation.


2 Answers

The animate(..) function' signature is:

.animate( properties, options ); 

And it says the following about the parameter properties:

properties A map of CSS properties that the animation will move toward.

text is not a CSS property, this is why the function isn't working as you expected.

Do you want to fade the text out? Do you want to move it? I might be able to provide an alternative.

Have a look at the following fiddle.

like image 159
Kevin Avatar answered Sep 28 '22 07:09

Kevin


$("#test").hide(100, function() {     $(this).html("......").show(100); }); 

Updated:

Another easy way:

$("#test").fadeOut(400, function() {     $(this).html("......").fadeIn(400); }); 
like image 43
jalmatari Avatar answered Sep 28 '22 08:09

jalmatari