CSS animation in email
Introduction
This example demonstrates how to perform several CSS transition animations in AMP for email.
Setup an Object to Animate
Set up some CSS for a square with rounded corners. This is the object we will be animating.
.object{ display: inline-block; border-radius: 20%; height: 100px; width: 100px; margin: 10px; }
Skew Animation
Hover on the square to see the object animate into a skewed position.
<div class="object skew"></div>
The following CSS defines an animation which skews the object -20 degrees (x,y). The transformation duration is set to 0.4 seconds and the animation effect is set to ease-in-out
.
.skew { background-color: #f53b57; transition: transform .4s ease-in-out; transform: skew(0deg, 0deg); } .skew:hover{ transition: transform .4s ease-in-out; transform: skew(-20deg, -20deg); }
Rotation Animation
Hover on the square to see the object rotate.
<span>
<div class="object rotate"></div>
<div class="object rotate origin"></div>
<div class="object rotate three-dimension"></div>
</span>
The following CSS defines a hover animation which rotates the object around differnt origin points, including a three dimensional rotation.
.rotate { background-color: #3c40c6; transition: transform .6s ease-in-out; } .rotate:hover{ transition: transform .9s ease-in-out; transform: rotate(280deg); } .rotate.origin { background-color: #3c40c6; transition: transform .6s ease-in-out; transform: rotate(0deg); transform-origin: top left; } .rotate.origin:hover{ transition: transform .9s ease-in-out; transform: rotate(-280deg); transform-origin: top left; } .rotate.three-dimension:hover{ transition: transform .9s ease-in-out; transform: rotate3d(1, 2, -1, 280deg) }
Translation Animation
Hover on the squares to see the objects animate to new positions.
<span>
<div class="object movexy one"></div>
<div class="object movexy two"></div>
<div class="object movexy three"></div>
</span>
The following CSS defines a translation animation which moves the object to a new position (x,y).
.movexy { background-color: #05c46b; transition: transform .4s ease-in-out; transform: translate(0px, 0px); } .movexy.one:hover{ transition: transform .4s ease-in-out; transform: translate(0px, -50px); } .movexy.two:hover{ transition: transform .4s ease-in-out; transform: translate(0px, 50px); } .movexy.three:hover{ transition: transform .4s ease-in-out; transform: translate(400px, -150px); }
Rolling an object
Hover on the square to see the object roll across the view..
<span>
<div class="object roll"></div>
</span>
The following CSS defines combines a transformation (rotation) with a translation animation to create a rolling effect.
.roll { background-color: #00d8d6; transition: transform 1.2s ease-in-out; } .roll:hover{ transition: transform 1.4s ease; transform: translate(530px, 0px) rotate(360deg); transition-timing-function: cubic-bezier(.55,.07,.42,.54); }
Scale Animation
Hover on the square to see the object animate into a new, larger size.
<div class="object scale"></div>
The following CSS defines an animation which scales the object's size.
.scale { background-color: #ffb8b8; transition: transform .4s ease-in-out; } .scale:hover{ transition: transform .4s ease-in-out; transform: scale(2); }
Down the drain
Hover on the squares to see the objects animate to new positions.
<span>
<div class="object drain"></div>
</span>
The following CSS combines a few different transformations and translations to create the effect of an object going down a drain.
.drain { background-color: #ffd32a; transition: transform 1.4s ease-in-out; } .drain:hover{ transition: transform 1.4s ease-in-out; transform: scale(0) skew(-20deg) rotate(-90deg) translate(430px, 220px); transition-delay: .2s; }
이 페이지의 설명만으로 궁금한 점이 모두 해결되지 않는다면 다른 AMP 사용자에게 문의하여 구체적인 활용 사례를 논의해 보세요.
Stack Overflow로 이동 설명이 부족한 기능을 발견하셨나요?AMP 프로젝트는 여러분의 참여와 기여를 적극 환영합니다! 오픈 소스 커뮤니티를 통해 지속적으로 활동해 주셔도 좋지만 관심 있는 주제에 한 번만 기여하셔도 큰 도움이 됩니다.
GitHub에서 샘플 수정하기