background-color with animation and pulse

0

Hello! Good afternoon. I am trying to provoke the following effect: when passing the mouse over a "a" tag, the background-color of the parent div in which this "a" tag is daughter, may change in transition but in a circular format where this circle would start from the "a" tag and expand until reaching the whole div. It's like a transition background-color radial gradient.

I thought about creating an invisible circular white element as the parent of the "a" tag but the daughter of the larger div. The structure would be:

<main>
  <article>
    <div class="box-de-texto" id="div-servicos">

     <p>texto...<p>
      <circle>
       <a>clique aqui</a>
      </circle>
     <p> mais texto>

    </div>
  </article>
</main>

In CSS, I did the following:

#div-servicos {
    transition: all 150ms ease;

}

circle {
    border-radius: 50%;
    position: relative;
    max-width: 100%;
    max-height: 100%;
}

and in Js:

var a = document.getElementById("aLink");
var div = document.getElementById("div-servicos");
var circle = document.getElementById("circle");

$(a).on("mouseover", function(){
    div.setAttribute("style","background-color: rgba(20,94,69,1.00); color: white;");
    circle.setAttribute("style","transform: scale(25); background-color: white;");
});

With this, I was able to create the effect of:

To:

Thebigproblemisthatevenputtingthe"transform: scale (25)" attribute on Js, it does not seem to be working in the "circle" I created.

The problem is almost solved and I was able to insert a change in the color of the text inside the "p" tag when the animation occurs but I think I need to play the "p" tag forward of the ripple class div layer with the suggestion of the comment below).

    
asked by anonymous 05.08.2018 / 21:04

1 answer

1

Based on on this answer from SOen :

jQuery(function($) {

  // MAD-RIPPLE // (jQ+CSS)
  $("[data-ripple]").hover(function(e) {
    
    var $self = $(this.parentNode);
    var $color = $(this).data("ripple");
    
    if($self.is(".btn-disabled")) {
      return;
    }
    if($self.closest("[data-ripple]")) {
      e.stopPropagation();
    }
    
    var initPos = $self.css("position"),
        offs = $self.offset(),
        x = e.pageX - offs.left,
        y = e.pageY - offs.top,
        dia = Math.min(this.offsetHeight, this.offsetWidth, 100), // start diameter
        $ripple = $('<div/>', {class : "ripple",appendTo : $self });
    
    if(!initPos || initPos==="static") {
      $self.css({position:"relative"});
    }
    
    $('<div/>', {
      class : "rippleWave",
      css : {
        background: $color,
        width: dia,
        height: dia,
        left: x - (dia/2),
        top: y - (dia/2),
      },
      appendTo : $ripple
    });
  }, function(e) {
    $('div.ripple').remove();
  });
});
/* No hover das tags com o atributo data-ripple, as tags p "do lado" ficam com a cor definida */
[data-ripple]:hover + p {
  color: red;
}

/* MAD-RIPPLE EFFECT */
.ripple{
  position: absolute;
  top:0; left:0; bottom:0; right:0;
  overflow: hidden;
  -webkit-transform: translateZ(0); /* to contain zoomed ripple */
  transform: translateZ(0);
  border-radius: inherit; /* inherit from parent (rounded buttons etc) */
  pointer-events: none; /* allow user interaction */
          animation: ripple-shadow 0.4s forwards;
  -webkit-animation: ripple-shadow 0.4s forwards;
}
.rippleWave{
  backface-visibility: hidden;
  position: absolute;
  border-radius: 50%;
  transform: scale(0.7); -webkit-transform: scale(0.7);
  background: rgba(255,255,255, 1);
  opacity: 0.45;
          animation: ripple 5s forwards;
  -webkit-animation: ripple 5s forwards;
}
@keyframes ripple-shadow {
  0%   {box-shadow: 0 0 0 rgba(0,0,0,0.0);}
  20%  {box-shadow: 0 4px 16px rgba(0,0,0,0.3);}
  100% {box-shadow: 0 0 0 rgba(0,0,0,0.0);}
}
@-webkit-keyframes ripple-shadow {
  0%   {box-shadow: 0 0 0 rgba(0,0,0,0.0);}
  20%  {box-shadow: 0 4px 16px rgba(0,0,0,0.3);}
  100% {box-shadow: 0 0 0 rgba(0,0,0,0.0);}
}
@keyframes ripple {
  to {transform: scale(999);}
}
@-webkit-keyframes ripple {
  to {-webkit-transform: scale(999);}
}
<script src="https://code.jquery.com/jquery-2.1.4.js"></script><div><h1>ClicktoRipple</h1><adata-ripple="rgba(0,0,0,1)">data-ripple</a>
  <p>More text</p>
</div>

<div>
  <h1>Click to Ripple</h1>
  <a data-ripple="rgba(0,255,0,0.5)">data-ripple</a>
  <p>More text</p>
</div>
    
05.08.2018 / 22:42