Claudia Claudia - 6 months ago 22
CSS Question

What CSS (or JS?) animation has this button?

I actually came across this theme on ThemeForest:
http://www.templatemonster.com/demo/58888.html

And I was wondering on how to achieve the animation effect the two buttons in the slider have (the 'buy intense now' and 'start a journey' buttons). I've checked the code behind it with Firebug, but had a little rough time understanding everything, so I tried to Google the animation and came across Hover.css. That wasn't exactly what I was looking for, so I was wondering if anybody can explain the way of achieving this effect?

Thanks in advance!

Answer

Have a look at the code below. You can adapt it to get the effect you want.

HTML:

<section id="button-container" class="section">
  <div id="effect" class="button">
    <span class="text">Button</span>
  </div>
</section>

CSS:

body, html {
  height: 100%;
  width: 100%;
}

*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
}

.section {
  float: left;
  font-family: 'Helvetica', sans-serif;
  height: 50%;
  width: 50%;
  display: flex;
  -webkit-display: flex;
  -webkit-align-items: center;
  align-items: center;
  justify-content: center;
  -webkit-justify-content: center;
}

.button {
  border: none;
  cursor: pointer;
  padding: 25px 50px;
  border: solid 1px gray;
  border-radius: 8px;
  position: relative;
}
.button .text {
  position: relative;
  z-index: 100;
  font-size: 2em;
}

#button-container {
  background-color: #fff;
}
#button-container #effect {
  background-color: #42b574;
  overflow: hidden;
}
#button-container #effect .text {
  color: #fff;
  transition: all .5s linear;
  -webkit-transition: all .5s linear;
}
#button-container #effect::after {
  content: '';
  position: absolute;
  transition: top .5s ease-in .5s, width .5s ease-out, height .5s ease-out;
  -webkit-transition: top .5s ease-in .5s, width .5s ease-out, height .5s ease-out;
  left: 50%;
  top: -50%;
  transform: translate(-50%, -50%);
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background-color: #79ccf2;
}
#button-container #effect:hover .text {
  color: #ffffff;
  transition: color .5s linear .5s;
  -webkit-transition: color .5s linear .5s;
}
#button-container #effect:hover::after {
  transition: top .5s ease-in, width .5s ease-out .5s, height .5s ease-out .5s;
  -webkit-transition: top .5s ease-in, width .5s ease-out .5s, height .5s ease-out .5s;
  top: 50%;
  width: 400px;
  height: 400px;
}

You can find the fiddle here