Cheap VPS & Xen Server


Residential Proxy Network - Hourly & Monthly Packages

jQuery UI Color Animation


jQuery UI adds some methods in core jQuery to extend the features of animate functionality. You can animate different transitions for an element. jQuery UI also supports animating colors. Here, you can animate one or more CSS properties that define an element colors.

Following is a list of CSS properties that support animate method.

  • backgroundColor :It is used to set the background color of the element.
  • borderTopColor :It is used to set the color for top side of the element border.
  • borderBottomColor :It is used to set the color for bottom side of the element border.
  • borderLeftColor :It is used to set the color for left side of the element border.
  • borderRightColor : It is used to set the color for right side of the element border.
  • color :It is used to set the text color of the element.
  • outlineColor : It is used to set the color for the outline; used to emphasize the element.

Syntax for the jQuery UI animate method:

  1. $( “#selector” ).animate(
  2.    { backgroundColor: “black”,
  3.       color: “white”
  4.    }
  5. );

If you want to add more than one property in this method, you will have to separate them with a comma.

Example of jQueryUI Color animation

Let’s take an example to demonstrate the color animate method with the use of addClass() method.

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset=“utf-8”>
  5. <title>jQuery UI addClass Example</title>
  6. <link href=“http://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css” rel=“stylesheet”>
  7. <script src=“http://code.jquery.com/jquery-1.10.2.js”></script>
  8. <script src=“http://code.jquery.com/ui/1.10.4/jquery-ui.js”></script>
  9. <style>
  10.  .elemClass {
  11. width: 200px;
  12. height: 50px;
  13. background-color: #b9cd6d;
  14. }
  15. .myClass {
  16. font-size: 40px; background-color: #ccc; color: white;
  17. }
  18. </style>
  19. <script type=“text/javascript”>
  20. $(document).ready(function() {
  21. $(‘#button-1’).click(function() {
  22. $(‘#animTarget’).animate({
  23. backgroundColor: “red”,
  24. color: “white”
  25. })
  26.  })
  27. });
  28. </script>
  29. </head>
  30. <body>
  31. <div id=animTarget class=“elemClass”>
  32. Hello Kreationnext </div>
  33. <button id=“button-1”>Click Me</button>
  34. </body>
  35. </html>

Test it Now

jQuery UI Color Animate with Toggle

Let’s take an example to demonstrate the color animate method with the use of toggle effect:

  1. <!doctype html>
  2. <html lang=“en”>
  3. <head>
  4.   <meta charset=“utf-8”>
  5.   <title>jQuery UI Effects – Animate demo</title>
  6.   <link rel=“stylesheet” href=“//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css”>
  7.   <script src=“//code.jquery.com/jquery-1.10.2.js”></script>
  8.   <script src=“//code.jquery.com/ui/1.11.4/jquery-ui.js”></script>
  9.   <link rel=“stylesheet” href=“/resources/demos/style.css”>
  10.   <style>
  11.     .toggler { width: 500px; height: 200px; position: relative; }
  12.     #button { padding: .5em 1em; text-decoration: none; }
  13.     #effect { width: 240px; height: 135px; padding: 0.4em; position: relative; background: #fff; }
  14.     #effect h3 { margin: 0; padding: 0.4em; text-align: center; }
  15.   </style>
  16.   <script>
  17.   $(function() {
  18.     var state = true;
  19.     $( “#button” ).click(function() {
  20.       if ( state ) {
  21.         $( “#effect” ).animate({
  22.           backgroundColor: “#aa0000”,
  23.           color: “#fff”,
  24.           width: 500
  25.         }, 1000 );
  26.       } else {
  27.         $( “#effect” ).animate({
  28.           backgroundColor: “#fff”,
  29.           color: “#000”,
  30.           width: 240
  31.         }, 1000 );
  32.       }
  33.       state = !state;
  34.     });
  35.   });
  36.   </script>
  37. </head>
  38. <body>
  39. <div class=“toggler”>
  40.   <div id=“effect” class=“ui-widget-content ui-corner-all”>
  41.     <h3 class=“ui-widget-header ui-corner-all”>Animate</h3>
  42.     <p>
  43.    jQuery is a fast, small, cross-platform and feature-rich JavaScript library. It is designed to simplify the client-side scripting of HTML.
  44. </p>
  45. </div>
  46. </div>
  47. <button id=“button” class=“ui-state-default ui-corner-all”>Toggle Effect</button>
  48. </body>
  49. </html>

Comments

comments