Jquery hover effect

How can I get the same effect as this

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

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

+3
source share
3 answers

Use hoverand animate. Please note that this requires a jQuery animation 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 a color change in an element, athere is no reason to use the crossfade effect used in the provided link.

+4
source

( CSS: z-). - :

/* 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();
  }
);

-

jQuery, CSS:

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>
+3

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

Here, the creator placed 2 images on top of each other, and then used 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");
  });
}); 
0
source

Source: https://habr.com/ru/post/1727900/