{"id":2263,"date":"2015-11-06T19:38:31","date_gmt":"2015-11-06T19:38:31","guid":{"rendered":"http:\/\/freshinbox.com\/blog\/?p=2263"},"modified":"2018-08-02T16:32:45","modified_gmt":"2018-08-02T16:32:45","slug":"css-animation-entrance-effects-in-email","status":"publish","type":"post","link":"https:\/\/freshinbox.com\/blog\/css-animation-entrance-effects-in-email\/","title":{"rendered":"CSS Animation Entrance Effects in Email"},"content":{"rendered":"<div class=\"effects\">\n<table width=\"100%\" border=0 cellpadding=10 cellspacing=0>\n<tr>\n<td bgcolor=\"#404040\" align=center style=\"font-family: Helvetica, sans-serif; font-size:23px;text-align:center;color:#ffffff; text-shadow: 2px 2px #111111;\"><BR><\/p>\n<div class=\"intro1\" style=\"height:40px;\">Introducing<\/div>\n<div class=\"intro2\" style=\"height:40px;font-size:27px;\">CSS Animation<\/div>\n<div class=\"intropop\" style=\"height:40px;font-size:32px;\">Entrance Effects<\/div>\n<p><img decoding=\"async\" class=\"delorean\" width=200 src=\"https:\/\/freshinbox.com\/images\/ext\/delorean2.png\">\n<\/td>\n<\/tr>\n<\/table>\n<\/div>\n<div style=\"text-align:center;\"><a style=\"font-weight:bold;\" href=\"https:\/\/codepen.io\/freshinbox\/pen\/djeZvg\" target=_new>Codepen Link<\/a><\/div>\n<div id=\"email-me\">\n  <input type=email id=\"email-me-email\" placeholder=\"Email address\"> <input id=\"email-me-btn\" type=button value=\"See Example In Your Inbox\" style=\"-webkit-appearance: none;\">\n<\/div>\n<p><BR><\/p>\n<p>Entrance effects using CSS animation can add some flair to your email.  Unlike more ambitious <a href=\"https:\/\/freshinbox.com\/blog\/the-dawn-of-kinetic-email\/\">kinetic email designs<\/a> that may involve a lot of development time including the production of both kinetic and fallback versions of an email, entrance animation effects leveraging CSS 2D transforms can deliver some pizzaz without a lot of extra effort.<\/p>\n<p>For this post, we&#8217;ll cover two kinds of entrance effects, fly-in and pop-in.<\/p>\n<p>Read this article for more background on <a href=\"https:\/\/freshinbox.com\/blog\/css-animations-in-email-and-vendor-prefixes\/\">CSS animations in email<\/a> including support in email clients.<BR><BR><\/p>\n<h4>Entrance Effects<\/h4>\n<p>Everyone has seen entrance effects used in slides and presentations where content slides in or fades into the presentation. Although CSS animation support is limited to more modern email clients, these entrance effects are relatively simple to implement and may provide a cool effect to your email depending on your audience.<\/p>\n<p>The key to these examples below is that you can just code your emails the way you&#8217;re used to and only need to wrap the elements you want the effect with a div to have them come alive in  email clients that <a href=\"https:\/\/freshinbox.com\/resources\/css.php\">support CSS animation<\/a>.<br \/>\n<BR><BR><\/p>\n<h4>Fly-in<\/h4>\n<p><BR><\/p>\n<div class=\"animbox\">\n<div class=\"fly-in-left\">Fly from left<\/div>\n<\/div>\n<p><span style=\"color:#555555\">(Animation above repeats for illustration purposes)<\/span><BR><BR><\/p>\n<p>The fly-in or slide-in effect allows your content to fly-in from any direction. We&#8217;re going to use the <a href=\"http:\/\/www.paulirish.com\/2012\/why-moving-elements-with-translate-is-better-than-posabs-topleft\/\">CSS 2D Transform <code>translate()<\/code> function<\/a> to achieve this effect.<\/p>\n<p>Although you can use other methods such as margin and absolute positioning to perform the fly-in animation, translate allows an element to be moved relative to its original position <strong>without affecting the elements around it<\/strong>. <\/p>\n<p>With 2D Transforms the element can grow, move or shrink and the elements around it behave as if the element has not moved. This is great since you don&#8217;t have to design your emails any differently to accommodate entrance effects.<\/p>\n<p>Note we&#8217;re using <code>-webkit-<\/code> vendor prefixes because as of this posting that is the only kind of animation declaration supported by <a href=\"https:\/\/freshinbox.com\/blog\/css-animations-in-email-and-vendor-prefixes\/\">email clients that support CSS animations<\/a>. Add these in a <code>&lt;style&gt;<\/code> block:<\/p>\n<pre class=\"lang:default decode:true \" >.fly-in-left{\r\n  -webkit-animation: flyinleftanim 1s ease; \r\n}\r\n@-webkit-keyframes flyinleftanim\r\n{\r\n  0% {-webkit-transform: translateX(-1000px);}       \r\n  100% {-webkit-transform: translateX(0px);}\r\n}<\/pre>\n<p>Then we wrap any element we want to &#8220;fly-in&#8221; with a div with the class &#8220;fly-in-left&#8221;. Now email clients that don&#8217;t support CSS animations will just display the content statically and clients that support CSS animations will display the content flying in from the left.<\/p>\n<pre class=\"lang:default decode:true \" > \r\n&lt;div class=\"fly-in-left\"&gt;Fly from left&lt;\/div&gt;\r\n\r\n<\/pre>\n<p><BR><BR> <\/p>\n<p><b>Adding a delay<\/b><\/p>\n<p>What if we want to add a delay before having the element &#8220;fly-in&#8221;? The obvious technique would be to add an <code>animation-delay<\/code> property. However that would mean the content would be displayed for a brief moment before the fly-ing in &#8211; not what we want.<\/p>\n<p>We could address the issue above by styling it so the element is hidden before executing the animation, but the animation would revert to being hidden after it completes!<\/p>\n<p>We could address the next issue with <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/animation-fill-mode\"><code>animation-fill-mode: forwards;<\/code><\/a>. Which would leave the element visible at the end of the animation&#8230; BUT&#8230; this isn&#8217;t supported by some old Android clients (specifically 2.x &#8211; if you don&#8217;t need that support you can use this method).<\/p>\n<p>Our solution to the delay is to let the animation &#8220;do nothing&#8221; for a percentage of the time. The following 3 second animation starts the 1 second long fly-in at the 2 second (66%) mark.<\/p>\n<pre class=\"lang:default decode:true \" >.fly-in-left{\r\n  -webkit-animation: flyinleftanim 3s ease; \r\n}\r\n@-webkit-keyframes flyinleftanim\r\n{\r\n  0% {-webkit-transform: translateX(-1000px);}       \r\n  66% {-webkit-transform: translateX(-1000px);}       \r\n  100% {-webkit-transform: translateX(0px);}\r\n}<\/pre>\n<p><BR><BR><\/p>\n<p><b>Bounding the animation<\/b><\/p>\n<p>By default the elements will fly-in from the edge of the email. However if you&#8217;d prefer to have the fly-in effect from the edges of say a hero box, then add <code>overflow: hidden<\/code> to the bounding area.<\/p>\n<p>On iOS, if you want an element to fly in from the right, you would need to wrap the animation within a bounding area with overflow set to hidden as well. Otherwise iOS will zoom out the email to display the initial location of the element &#8220;flying in&#8221; from the right.<BR><BR><\/p>\n<h4>Pop-in<\/h4>\n<div class=\"animbox\">\n<div class=\"pop-in\">Pop In!<\/div>\n<\/div>\n<p><BR><\/p>\n<p>The pop-in effect is a combination of a fade-in and a quick grow and shrink animation. It uses the opacity style to fade in and the scale 2D transform to start the scaling from 75% of its size to 120% back to 100% to deliver the &#8220;pop&#8221;. Using the scale 2D transform vs using widths and heights &#8211; as mentioned in the last section allows the element to grow and shrink without affecting its surrounding elements.<\/p>\n<p>As you can see from the code below, there&#8217;s a significant time where the animation does &#8220;nothing&#8221; from 0-93%. That is so that we can spring the animation at the close to 2 second point. Modify these values to suit your needs. You can also use the animation-delay property subject to the caveats mentioned in the previous section.<\/p>\n<pre class=\"lang:default decode:true \" >.pop-in{\r\n  -webkit-animation: popinanim 2s ease; \r\n}\r\n\r\n@-webkit-keyframes popinanim{\r\n  0% { \r\n    opacity:0;\r\n    -webkit-transform: scale(0.75);\r\n  }        \r\n  93% { \r\n    opacity:0;\r\n    -webkit-transform: scale(0.75);\r\n  }        \r\n  98% { \r\n    opacity:1;\r\n    -webkit-transform: scale(1.2);\r\n  }\r\n  100% { \r\n    opacity:1;\r\n    -webkit-transform: scale(1);\r\n  }\r\n} <\/pre>\n<p><BR><BR> <\/p>\n<h4>Where to learn more<\/h4>\n<p>Aside from getting some of the basics of using animation in email in the<br \/>\n<a href=\"https:\/\/freshinbox.com\/blog\/css-animations-in-email-and-vendor-prefixes\/\">last article<\/a>, here are some other resources you can use.<\/p>\n<ul>\n<li><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/CSS_Animations\/Using_CSS_animations\">CSS Animation Reference<\/li>\n<li><a href=\"http:\/\/www.w3schools.com\/cssref\/css3_pr_transform.asp\">CSS Transforms<\/li>\n<li><a href=\"https:\/\/daneden.github.io\/animate.css\/\">Daniel Eden&#8217;s Animate.CSS Entrance Effects<\/a><\/li>\n<li><a href=\"https:\/\/css-tricks.com\/almanac\/properties\/t\/transform\/\n\">CSS Transforms Demos at CSS Tricks<\/a><\/li>\n<li><a href=\"https:\/\/desandro.github.io\/3dtransforms\/\">Feeling ambitious? 3D Transforms!<\/a><\/li>\n<\/ul>\n<p><BR><BR><BR><\/p>\n<div style=\"color:#888888;\">Credit: <a href=\"https:\/\/openclipart.org\/detail\/24464\/car-delorean\">raulxav<\/a> for the Delorean image<\/div>\n<p><BR><BR><br \/>\n<div style=\"padding:10px; border: 2px solid #99C731;background-color:#FFF8DC;border-radius:5px;\">\n<form action=\"https:\/\/freshinbox1.createsend.com\/t\/i\/s\/adrmi\/\" method=\"post\" id=\"subForm\">\n<span class=\"fisub_header\" style=\"font-weight:bold;\">Subscribe to the #EmailGeeks Newsletter<\/span>\n<p><input id=\"fieldEmail\" name=\"cm-adrmi-adrmi\" type=\"email\" style=\"width:90%\" required placeholder=\"Your Email Address\" \/><\/p>\n<p><button type=\"submit\">Subscribe<\/button><\/p>\n<\/form>\n<\/div><\/p>\n<style>\n.animbox{\nbackground-color:#404040;\nwidth:100%;\nmin-width:400px;\npadding:20px 0px;\ntext-align:center;\n}\n.fly-in-left{\n  color:#ffffff;\n  font-size:30px;\n  text-shadow: 2px 2px #555555;\n  -webkit-animation: flyinleftanim 5s ease infinite; \n  animation: flyinleftanim 5s ease infinite; \n}\n@-webkit-keyframes flyinleftanim\n{\n  0% {-webkit-transform: translateX(-1000px);}       \n  20% {-webkit-transform: translateX(0px);}       \n  100% {-webkit-transform: translateX(0px);}\n}\n@keyframes flyinleftanim\n{\n  0% {transform: translateX(-1000px);}       \n  20% {transform: translateX(0px);}       \n  100% {transform: translateX(0px);}\n}\n.pop-in{\n  color:#ffffff;\n  font-size:30px;\n  text-shadow: 2px 2px #555555;\n  -webkit-animation: popinanim 5s ease infinite; \n  animation: popinanim 5s ease infinite; \n}\n@-webkit-keyframes popinanim\n{\n  0% { opacity:0; -webkit-transform: scale(0.75);}        \n  50% { opacity:0; -webkit-transform: scale(0.75);}        \n  52% {  opacity:1; -webkit-transform: scale(1.2);}\n  53% { opacity:1; -webkit-transform: scale(1);}\n  100% { opacity:1;-webkit-transform: scale(1);}\n}\n@keyframes popinanim\n{\n  0% { opacity:0; transform: scale(0.75);}        \n  50% { opacity:0; transform: scale(0.75);}        \n  52% {  opacity:1; transform: scale(1.2);}\n  53% { opacity:1; transform: scale(1);}\n  100% { opacity:1; transform: scale(1);}\n}\n<\/style>\n<style>\n  .effects{\n    position:relative;\n    overflow:hidden;\n  }\n  .intro1{\n     -webkit-animation: flytop1 8s ease infinite; \n     animation: flytop1 8s ease infinite; \n  }\n  .intro2{\n     -webkit-animation: flytop2 8s ease infinite; \n     animation: flytop2 8s ease infinite; \n  }\n  @-webkit-keyframes flytop1\n  {\n    0% {-webkit-transform: translateY(-1000px);}\n    10% {-webkit-transform: translateY(-1000px);}       \n    17% {-webkit-transform: translateY(0px);}\n    100% {-webkit-transform: translateY(0px);}\n  }\n  @-webkit-keyframes flytop2\n  {\n    0% {-webkit-transform: translateY(-1000px);}\n    22% {-webkit-transform: translateY(-1000px);}       \n    30% {-webkit-transform: translateY(0px);}\n    100% {-webkit-transform: translateY(0px);}\n  }  \n  @keyframes flytop1\n  {\n    0% {transform: translateY(-1000px);}\n    10% {transform: translateY(-1000px);}       \n    17% {transform: translateY(0px);}\n    100% {transform: translateY(0px);}\n  }\n  @keyframes flytop2\n  {\n    0% {transform: translateY(-1000px);}\n    22% {transform: translateY(-1000px);}       \n    30% {transform: translateY(0px);}\n    100% {transform: translateY(0px);}\n  }  \n  .intropop{\n    -webkit-animation: showpop 8s ease infinite; \n    animation: showpop 8s ease infinite; \n  }\n  @-webkit-keyframes showpop\n  {\n    0% { \n      opacity:0;\n      -webkit-transform: scale(0.75);\n    }        \n    37% { \n      opacity:0;\n      -webkit-transform: scale(0.75);\n    }        \n    39% { \n      opacity:1;\n      -webkit-transform: scale(1.1);\n    }\n    40% { \n      opacity:1;\n      -webkit-transform: scale(1);\n    }\n    100% { \n      opacity:1;\n      -webkit-transform: scale(1);\n    }    \n  }\n  @keyframes showpop\n  {\n    0% { \n      opacity:0;\n      transform: scale(0.75);\n    }        \n    37% { \n      opacity:0;\n      transform: scale(0.75);\n    }        \n    39% { \n      opacity:1;\n      transform: scale(1.1);\n    }\n    40% { \n      opacity:1;\n      transform: scale(1);\n    }\n    100% { \n      opacity:1;\n      transform: scale(1);\n    }    \n  }  \n  .delorean{\n    -webkit-animation: slideright 8s ease infinite; \n    animation: slideright 8s ease infinite; \n  }\n  @-webkit-keyframes slideright\n  {\n    0% {-webkit-transform: translateX(1000px);}\n    50% {-webkit-transform: translateX(1000px);}       \n    60% {-webkit-transform: translateX(0px);}\n    100% {-webkit-transform: translateX(0px);}\n  }  \n  @keyframes slideright\n  {\n    0% {transform: translateX(1000px);}\n    50% {transform: translateX(1000px);}       \n    60% {transform: translateX(0px);}\n    100% {transform: translateX(0px);}\n  }  \n<\/style>\n<style>\n#email-me-email {\n  width:150px;\n  height:20px;\n  margin-bottom: 5px;\n  background-color: #FAFCEF;\n  font-size: 14px;\n  padding: 3px 5px;\n  display:inline-block;\n  border-radius:3px;\n  margin-left:20px;\n}\n#email-me-btn {\n  cursor: pointer;\n  font-size: 14px;\n  color: white;\n  text-decoration:none;\n  text-shadow:#555555 0 1px;\n  background-color: #7DC442;\n  padding: 5px 12px;\n  border:1px solid #559621;\n  border-radius: 5px;\n  display:inline-block;\n}\n#email-me-btn:hover {\n  background-color: #78D62C;\n}\n#email-me{\n  width: 400px;\n  padding:20px 0px;\n  xborder:3px solid #888888;\n  xborder-radius: 5px;\n  margin:0px auto;\n}\n<\/style>\n<p><script src=\"\/\/ajax.googleapis.com\/ajax\/libs\/jquery\/1.10.2\/jquery.min.js\"><\/script><br \/>\n<script>\n  var theEmail = null;\n  $(document).ready(function(){\n    $('#email-me-btn').click(function(){\n      theEmail = $('#email-me-email').val();\n      sendEmail(theEmail);\n    });\n    $(\"#email-me-email\").keypress(function(e) {\n      if(e.which == 13) {\n        theEmail = $('#email-me-email').val();        \n        sendEmail(theEmail);\n      }\n    });\n  });\n  var sendEmail = function(emailAddr){\n    if(!emailAddr || emailAddr.length < 12){\n      alert('Please enter an email');\n      return;\n    }\n    $('#email-me-email').val('sending...');\n    $.ajax({\n      url: \"https:\/\/freshinbox.com\/examples\/entrance-effects\/mail_example.php\",\n      data: {\n        email: emailAddr\n      },\n      success: function( data ) {\n        if(data == null || data.indexOf(\"ERROR\") != -1){\n          alert(\"There was a problem sending the email \\n\"+data);\n        }else{\n          alert(\"An email has been sent to \"+emailAddr+\"!\\n (Be sure to check the spam folder just in case)\");          \n        }\n        $('#email-me-email').val('');\n      }\n    });\n  }\n<\/script><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Entrance effects using CSS animation can add some flair to your email.  Unlike more ambitious <a href=\"http:\/\/freshinbox.com\/blog\/the-dawn-of-kinetic-email\/\">kinetic email designs<\/a> that may involve a lot of development time , entrance animation effects leveraging CSS 2D transforms can deliver some pizzaz without a lot of extra effort.<\/p>\n","protected":false},"author":2,"featured_media":2315,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[23,24,25,47],"tags":[],"_links":{"self":[{"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/posts\/2263"}],"collection":[{"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/comments?post=2263"}],"version-history":[{"count":56,"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/posts\/2263\/revisions"}],"predecessor-version":[{"id":3829,"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/posts\/2263\/revisions\/3829"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/media\/2315"}],"wp:attachment":[{"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/media?parent=2263"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/categories?post=2263"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/tags?post=2263"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}