High performance Animation "Box-shadow" property

Source: Internet
Author: User
Tags relative

This article from "How To animate" Box-shadow "with silky smooth performance" compiled, English no problem classmate, look at the original text to find original.
Case effect as shown in the figure below, the specific effect please go to the demo.
! [Case Presentation] (http://img.blog.csdn.net/20151123083204051

To improve animation performance, you should reduce the number of repaint pages. As a result, the shadow is pre-defined using a pseudo-object relative to the direct animation "Box-shadow" property, and the animation opacity implemented in a better way.

/* Slow way *
/. Make-it-slow {
  box-shadow:0 1px 2px rgba (0,0,0,0.15);
  Transition:box-shadow 0.3s ease-in-out:
}/

* Hover response */
. make-it-slow:hover {
  box-shadow:0 5px 15px RGBA (0,0,0,0.3);
}

/* Quick Way *
/. make-it-fast {
  box-shadow:0 1px 2px rgba (0,0,0,0.15);
}

/* Use pseudo-objects to pre-define shadows, but hide them first *
/. make-it-fast:after {
  box-shadow:0 5px 15px rgba (0,0,0,0.3);
  opacity:0;
  Transition:opacity 0.3s ease-in-out:
}/

* hover after display */
. make-it-fast:hover:after {
  opacity:1;
}

The full case effect is shown below.

. box {
  position:relative;
  Display:inline-block;
  width:100px;
  height:100px;
  Background-color: #fff;
  border-radius:5px;
  box-shadow:0 1px 2px rgba (0, 0, 0, 0.1);
  border-radius:5px;
  -webkit-transition:all 0.6s cubic-bezier (0.165, 0.84, 0.44, 1);
  Transition:all 0.6s cubic-bezier (0.165, 0.84, 0.44, 1);
}

. Box:after {
  content: "";
  border-radius:5px;
  Position:absolute;
  top:0;
  left:0;
  width:100%;
  height:100%;
  box-shadow:0 5px 15px rgba (0, 0, 0, 0.3);
  opacity:0;
  -webkit-transition:all 0.6s cubic-bezier (0.165, 0.84, 0.44, 1);
  Transition:all 0.6s cubic-bezier (0.165, 0.84, 0.44, 1)
}

. box:hover {
  -webkit-transform:scale (1.25, 1.25);
  Transform:scale (1.25, 1.25)
}

. box:hover:after {
    opacity:1
}

That's all.

Declaration
This article starts with the geek headline. Love front end, music share. Fedfun hope to make progress together with you.
Welcome any form of reprint, please indicate loading, keep this paragraph text.
Standalone Blog Http://whqet.github.io
Sina Weibo http://weibo.com/FedFun
Geek headlines

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.