Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Transparent isn't really a color. So, you can't animate to it. You might be able to achieve the effect you're looking for by using a separate element for the background, and animating the opacity though.</p> <h3>Example:</h3> <p>HTML:</p> <pre><code>&lt;body style="background-color:yellow"&gt; &lt;!-- by default, "see through" to parent's background color --&gt; &lt;div id="container"&gt; Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean nec magna. Nulla eu mi sit amet nibh pellentesque vehicula. Vivamus congue purus non purus. Nam cursus mollis lorem. &lt;/div&gt; &lt;/body&gt; </code></pre> <p>Script:</p> <pre><code>// on load... $(function() { var container = $("#container"); container .hover( // fade background div out when cursor enters, function() { $(".background", this).stop().animate({opacity:0}); }, // fade back in when cursor leaves function() { $(".background", this).stop().animate({opacity:1}) }) // allow positioning child div relative to parent .css('position', 'relative') // create and append background div // (initially visible, obscuring parent's background) .append( $("&lt;div&gt;") .attr('class', 'background') .css({ backgroundColor:'blue', position: 'absolute', top:0, left:0, zIndex:-1, width:container.width(), height:container.height() }) ); }); </code></pre> <hr> <p>Kingjeffrey's comment points out that this answer is somewhat outdated - browsers do now support RGBA color values, so you <em>can</em> animate just the background. However, jQuery doesn't support this in core - you'll need a <a href="http://pioupioum.fr/sandbox/jquery-color/" rel="nofollow noreferrer">plugin</a>. See also: <a href="https://stackoverflow.com/questions/3242368/jquery-rgba-color-animations">jQuery + RGBA color animations</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload