2

I created a call-to-action button that makes a small animation on click:

  1. Static and showing ADD TO CART
  2. On click: Background animation (duration 1sec) and content = 'Adding to cart'
  3. After 1sec: New background colour and showing ADDED TO CART Go to Cart

Button template:
See the button template

Basically, I used the ::after to change the background colour as a progress bar and ::before to the content to ADDING TO CART.

All works perfect BUT the text ADDING TO CART is blurry on the mobile version.

Print on the desktop and mobile:
See the print on desktop and mobile

The relevant code:

changeBtn() {
  addCartEl.classList.add('global__main-btn--active');
  addCartEl.innerHTML = "Added to cart<span>Go to cart</span>"
}
$('#add-to-cart').on('click', changeBtn());
@keyframes adding {
  0% {
    width: 0%;
    opacity: 1;
  }
  99% {
    width: 99%;
    opacity: 1;
  }
  100% {
    width: 100%;
    opacity: 0;
  }
}
@keyframes txt-adding {
  0% {
    opacity: 1;
  }
  80% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}
@keyframes added {
  0% {
    color: transparent;
    background-color: #6abf58;
  }
  100% {
    color: #b4dfab;
    background-color: #3f7634;
  }
}
.global__main-btn {
  font-size: 20pt;
  font-weight: 700;
  text-transform: uppercase;
  color: white;
  background-color: green;
  padding: 1rem 5rem;
  width: 100%;
  border-radius: 0.5rem;
  border: 1px solid green;
  border-bottom: 4px solid green;
  margin-bottom: 0.5rem;
  max-width: 450px;
}
.global__main-btn::before {
  content: "";
  background-color: white;
  mask-image: url("../assets/svg/cart-plus-solid.svg");
  position: relative;
  float: left;
  width: 30px;
  height: 27px;
}
.global__main-btn:hover {
  box-shadow: inset 0 0 4rem green;
  cursor: pointer;
}
.global__main-btn--active {
  border: none;
  padding: 0.6rem 5rem;
  position: relative;
  color: transparent;
  animation: added 0.2s 0.8s normal linear forwards;
  min-height: 66px;
}
.global__main-btn--active span {
  display: block;
  font-weight: 300;
  font-size: 12pt;
}
.global__main-btn--active:hover {
  box-shadow: inset 0 0 4rem green;
}
.global__main-btn--active::before {
  content: "";
  width: 100%;
  height: 100%;
  background-color: green;
  border-radius: 0.5rem;
  position: absolute;
  top: 0;
  left: 0;
  mask-image: none;
  animation: adding 1s normal linear forwards;
}
.global__main-btn--active::after {
  content: "Adding to cart";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translateX(-50%) translateY(-50%);
  width: 100%;
  color: white;
  animation: txt-adding 1s normal linear forwards;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button type="submit" class="buy__btn global__main-btn" id="add-to-cart">Add to cart</button>
TylerH
  • 20,799
  • 66
  • 75
  • 101
Rafael Perozin
  • 573
  • 7
  • 20
  • Also not seeing anything blurry, between mobile and desktop versions of the screenshots.. – estinamir Feb 26 '19 at 16:29
  • This may not be your issue, but try adding `* { -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }` to the top of your SASS file. – disinfor Feb 26 '19 at 16:56
  • 1
    @bestinamir Sorry but I believe that the image optimization makes all a bit blurry. But in the dev environment looks as I made intentionally just on the mobile button. – Rafael Perozin Feb 27 '19 at 09:08
  • @disinfor I did it right now, improved the sharpness but not enough. Any other idea? – Rafael Perozin Feb 27 '19 at 09:12
  • @BraDev, i had a similar issue and figured it has to do with the transform property. As soon as i added a transformation, the text got blurry. Try it without the transformation. If that is the reason for you as well, you have to figure out a different approach to position the text in that case. – LeaveAirykson Feb 27 '19 at 14:19

1 Answers1

2

I had a similar issue and figured it has to do with the transform property. As soon as i added a transformation, the text got blurry. Removing it will solve the problem. This seems to be a webkit or blink engine bug.