Changing text color with JQuery animation

Is there a way to animate text color using jQuery/jQuery UI? I want the text color to change from #000 to #F00 when an event is triggered, then fade back to #000 over 3 seconds.

I attempted using effect("highlight", {}, 3000) with the highlight effect, but it doesn't re-trigger until completion and will continue for the same duration of time. This isn't ideal for my needs.

Any suggestions?

C

UPDATE:

This is my current attempt:

$("input:text[name=size_w]").keyup(function () {
            var value = ($("input:text[name=size_w]").val() == "") ? "null" : $("input:text[name=size_w]").val();
            $("#width_emb").text(value).css({ color: "red" }).animate({ color: "black" }, 3000);
        }).keyup();

However, it still doesn't function as desired. I am unable to re-trigger the initial color change until the animation is complete. If the event is triggered again before 3 seconds, I need to cancel the animation and restart it.

Answer №1

If you're looking to add color animation support, consider implementing JQueryUI.

http://jqueryui.com/demos/animate/

According to the JQueryUI site:

The jQuery UI effects core extends the animate function to be able to animate colors as well. It's heavily used by the class transition feature and it's able to color animate various properties such as backgroundColor, borderBottomColor, borderLeftColor, borderRightColor, borderTopColor, color, and outlineColor.

In response to an updated question regarding interrupting or restarting halfway through an animation, you can achieve this by calling .stop() http://api.jquery.com/stop/ This method can also be used to clear any queued animations.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

I keep encountering the error message "$(".dropdown-toggle").dropdown is not a function" while attempting to use Dropdowns with Jade and Bootstrap

I am attempting to implement a Bootstrap dropdown in my Jade layout. However, I keep encountering an error when trying to run $(".dropdown-toggle").dropdown in my Jade file: $ is undefined $(".dropdown-toggle").dropdown is not a function What could be ...

ReactJS how to prevent accordion from collapsing automatically

My custom accordion layout for the features needed in the site I am building is not working well with Jquery. How can I modify it to collapse properly? Specifically, I want it so that when I open number 2, number 1 will automatically close. I've trie ...

Ways to implement a resize function in Angular JS without relying on the document and window objects

Is there a way to convert the following jQuery code into Angular JS without relying on Document and Window? Can we write the code without utilizing Document.ready and window? ...

PHP is returning a null value as the last value, but JQuery is able to correctly select the last row from the

I'm currently facing a challenge in passing variables from HTML/PHP to jQuery for AJAX. Below is the code snippet: <?php $propertyid = $data['property_id']; $select5 = $con->prepare("SELECT favorite_properties_id, favorite_pro ...

What is the best way to upload a canvas image from a GUI to the back-end using an AJAX call and setting the content-type as "image/jpeg"?

What is the best method for saving a canvas image from GUI to back-end using an AJAX call that accepts content type "image/jpeg" and avoids the error "jquery.js: 8453 Uncaught TypeError: Illegal invocation?" HTML <canvas id="myImage"></canvas> ...

Utilizing the power of Vue 2 and NuxtJS to effortlessly customize the appearance of child components

I am currently working on a Nuxt.js project (still using Vue 2) that consists of two components. I am trying to override the child style with the parent's style, but the ::v-deep pseudo selector doesn't seem to be effective. Regardless of my eff ...

What is stopping me from utilizing ES6 template literals with the .css() method in my code?

I am currently working on a project where I need to dynamically create grid blocks and change the color of each block. I have been using jQuery and ES6 for this task, but I am facing an issue with dynamically changing the colors. Below is the snippet of m ...

Trigger a popup notification with JavaScript when

Check out this snippet of code: <link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"> <script src="https://code.jquery.com/jquery-1.12.4.js"></script> <script src="https://code.jquery.com/ui/ ...

Looking for assistance with aligning an image in a <td> cell that doubles as a link?

How can I center a play icon in the middle of a td cell and make the entire content clickable as a link, including the background image? I've tried various methods but can't seem to get it right without breaking the alignment. Any suggestions wou ...

Creating a dynamic pulse effect using jQuery to manipulate CSS box-shadow

My goal is to create a pulsating effect using CSS box-shadow through jQuery. Despite my best efforts, the code I attempted failed to produce the desired smooth pulse effect with box-shadow. The code snippet I experimented with: <div class="one"> &l ...

Issue with Jquery modal not functioning properly on second attempt

Currently, I am working on developing an application using CodeIgniter. However, I have encountered a problem where the modal window does not open for the second time. Here is a more detailed explanation of the issue: The form (view) in question contains ...

The CSS attribute selector is unable to target dynamically appended class names

Utilizing React's CSS animations add-on has been a seamless process, with everything running smoothly when using the provided classnames. .quote-enter { opacity: 0.01; transition: opacity .25s ease-in; } .quote-enter.quote-enter-active { opaci ...

What is the best way to store a range object obtained from getSelection in order to recreate it on a separate page load?

My goal is to develop a web application that enables users to highlight selected text on a webpage with the click of a button. I want these highlights to persist even when the user returns to the page. So far, I have achieved: var selectedRange = documen ...

Encountering a Django Ajax HTTP 500 Error

I'm struggling to integrate Django with AJAX requests, and I keep getting an HTTP 500 error related to MultiValueDictKeyError even though everything seems fine? I passed in 3 variables: sendEmail, username, error When accessing request.POST on the 3 ...

Issue with jQuery behaving unexpectedly during Ajax requests

Using jQuery/PHP/MySql, I have successfully implemented a feature to load Twitter search results on my page. The initial load is limited to the first 20 search results. As the user scrolls down the page and reaches the bottom, an additional 20 results are ...

Ensure the detection of 404 error status using jQuery

My current approach involves using this code snippet to retrieve data from Twitter through its API: $.ajax({ url : apiUrl, cache : false, crossDomain: true, dataType: "jsonp", success : f ...

The alignment of Div elements is off in IE8

I have been struggling to align two divs side by side without any empty spaces on IE 8. Everything looks perfect on Chrome Version 35.0.1916.153 m and Firefox 30.0, but IE 8 seems to be causing some issues. All I want is a main div with two child divs ali ...

use ajax to post saved data to a WebAPI in php

I have successfully implemented the code to save data in a custom table using Ajax. Now, I need to figure out how to send this data to an asp.Net API using js/jQuery. How can I achieve this? Below is my HTML form and JS code: <div id="inline1" class= ...

Steps for building a Bootstrap grid of thumbnails

I need to display an unknown number of thumbs. Below is a sample of the HTML rendered: <div class="row-fluid"> <ul class="thumbnails"> <li class="span3"> <a href="#" class="thumbnail"> &l ...

Unusual characteristics of decision-making

Here is a snippet of my JavaScript code: function getSelectedText(){ if(window.getSelection){ select = window.getSelection().getRangeAt(0); var st_span = select.startContainer.parentNode.getAttribute("id").split("_") ...