3

How can I get same effect like this

http://bavotasan.com/demos/fadehover/

But only for anchor tags not for images, let say I have anchor background blue and I want it to change to red but with this effect, how can I do that? thank you

3 Answers 3

4

Use hover and animate. Note that this requires the jQuery color animations plugin.

<html>
<head>
  <title>color change</title>
  <script type="text/javascript" src="http://code.jquery.com/jquery.js"></script>
  <script src="http://plugins.jquery.com/files/jquery.color.js.txt" type="text/javascript" charset="utf-8"></script>
  <script type="text/javascript" charset="utf-8">
    $(function() {
      $('a').hover(function() {
        $(this).animate({
          color: "#f00"
        }, "fast")
      }, function() {
        $(this).animate({
          color: "#00f"
        }, "fast")
      });
    });
  </script>
  <style>
    a { color: #00f; }
  </style>
</head>
<body>
  <a href="#">This changes color on hover.</a>
</body>
</html>

In the example of changing color on an a element there is no reason to use the crossfade effect used in the link you provide.

Sign up to request clarification or add additional context in comments.

Comments

3

Placing two images on top of eachother (via CSS: position and z-index). A black and white one, and a color one:

/* Assumes width and height are the same between all three elements */
.viewBox  { position:relative; width:125px; height:125px; display:block; }
img.color { position:absolute; top:0; left:0; z-index:10; }
img.bandw { position:absolute; top:0; left:0; }

<a class="viewBox" href="http://google.com">
  <img src="color.jpg" class="color" />
  <img src="bandw.jpg" class="bandw" />
</a>

$(".viewBox").hover(
  function() {
    $("img.color").fadeIn();
  },
  function() {
    $("img.color").fadeOut();
  }
);

--

Alternatively, you can accomplish this without jQuery, using pure css too:

span.hov span            { display:none; }
.rollover                { display:block; background-image:url('bandw.jpg'); 
                           width:125px; height:125px; }
.rollover span.hov       { display:none;  background-image:url('color.jpg');
                           width:125px; height:125px; }
.rollover:hover span.hov { display:block; }

<a class="rollover">
  <span class="hov">
    <span>Invisible Link Text</span>
  </span>
</a>

1 Comment

My question is how can do it with <a> tags , and you are opening <div> and closing </a> .. tnx
0

The HTML, CSS and jQuery is available on the web page for you.

Here, the creator has layed 2 images on top of each other then uses jQuery to change the opacity.

<div class="fadehover">
  <img class="a" alt="" src="cbavota-bw.jpg" style="opacity: 1;"/>
  <img class="b" alt="" src="cbavota.jpg"/>
</div>

$(document).ready(function(){
  $(".a").hover(function() {
    $(this).animate({"opacity": "0"}, "slow");
  },
  function() {
    $(this).animate({"opacity": "1"}, "slow");
  });
}); 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.