{"id":2417,"date":"2016-01-11T22:52:03","date_gmt":"2016-01-11T22:52:03","guid":{"rendered":"http:\/\/freshinbox.com\/blog\/?p=2417"},"modified":"2016-01-21T01:14:31","modified_gmt":"2016-01-21T01:14:31","slug":"ambient-animations-in-email-snow-and-stars","status":"publish","type":"post","link":"https:\/\/freshinbox.com\/blog\/ambient-animations-in-email-snow-and-stars\/","title":{"rendered":"Ambient Animations in Email: Snow and Stars"},"content":{"rendered":"<p>Its the holidays and emails take on a certain holiday spirit. Logos take on some holiday cheer, reds and greens are added to the color palette and snow!<\/p>\n<p>This is also the time where falling snow animations are added to emails. In the past this would involve animated gifs, but these days campaigns are incorporating CSS animations to bring that snowfall effect. However there&#8217;s more than one way to implement ambient animations. For the most part these techniques are no different than regular animations on the web &#8211; you only need to make sure to take into account clients that <a href=\"https:\/\/freshinbox.com\/resources\/css.php\">don&#8217;t support animations<\/a>.<BR><BR><\/p>\n<h4>Animating individual snowflakes<\/h4>\n<p><BR><\/p>\n<p><a href=\"https:\/\/freshinbox.com\/blog\/wp-content\/uploads\/2015\/07\/bnq-snow-anim.gif\"><img decoding=\"async\" src=\"https:\/\/freshinbox.com\/blog\/wp-content\/uploads\/2015\/07\/bnq-snow-anim.gif\" alt=\"bnq-snow-anim\" width=\"400\" class=\"aligncenter size-full wp-image-1963\" \/><\/a><BR><\/p>\n<p>This campaign from B&#038;Q actually came out in 2014 and it features snow falling across the email.<\/p>\n<p>The implementation is fairly straightforward, you create a bunch of square white divs, set the border-radius to half of its height to make the div round and then animate the divs using absolute positioning from the top to bottom. If you want to bound the snow, wrap it within a container that has the position set to relative.<\/p>\n<pre class=\"lang:default decode:true \" >&lt;div class=\"animcontainer\"&gt;\r\n  &lt;div class=\"snow snow1\"&gt;&lt;\/div&gt;\r\n  &lt;div class=\"snow snow2\"&gt;&lt;\/div&gt;\r\n  &lt;div class=\"snow snow3\"&gt;&lt;\/div&gt;\r\n&lt;\/div&gt;<\/pre>\n<p>One trick to making the snow appear random is to set the duration of each animation to be different from the rest so it becomes random even after the animation repeats. Also since <a href=\"https:\/\/freshinbox.com\/blog\/css-animations-in-email-and-vendor-prefixes\/\">only webkit based email clients<\/a> are able to view the animation, we wrap the CSS with a webkit media query and use the -webkit vendor prefix. <\/p>\n<pre class=\"lang:default decode:true \" >&lt;style&gt;\r\n@media screen and (-webkit-min-device-pixel-ratio: 0) {\r\n .animcontainer{\r\n  position:relative;\r\n  width:100%;\r\n  height:200px;\r\n  overflow:hidden;\r\n  background-color:#007FFF;\r\n }\r\n .snow{\r\n  border-radius:9px;\r\n  height:18px;\r\n  width:18px;\r\n  position:absolute;\r\n  top:-20px;\r\n  background-color:#ffffff;\r\n }\r\n .snow1{\r\n  -webkit-animation: snowanim1 5s linear 0s infinite; \r\n }\r\n .snow2{\r\n  -webkit-animation: snowanim2 6s linear 1s infinite; \r\n }\r\n .snow3{\r\n  -webkit-animation: snowanim3 7s linear 2s infinite; \r\n }\r\n @-webkit-keyframes snowanim1\r\n {\r\n  0% { top:0%;left:50%; }        \r\n  100% { top:100%;left:65%; }\r\n }\r\n @-webkit-keyframes snowanim2\r\n {\r\n  0% { top:0%;left:30%; }        \r\n  100% { top:100%;left:25%; }\r\n }\r\n @-webkit-keyframes snowanim3\r\n {\r\n  0% { top:0%;left:70%; }        \r\n  100% { top:100%;left:60%; }\r\n }\r\n}\r\n&lt;\/style&gt;<\/pre>\n<style>\n.snow{\n  border-radius:9px;\n  height:18px;\n  width:18px;\n  position:absolute;\n  top:-20px;\n  background-color:#ffffff;\n}\n.animcontainer{\n  position:relative;\n  width:90%;\n  margin: 0px auto;\n  height:200px;\n  overflow:hidden;\n  background-color:#007FFF;\n}\n.snow1{\n  -webkit-animation: snowanim1 5s linear 0s infinite; \n  animation: snowanim1 5s linear 0s infinite; \n}\n.snow2{\n  -webkit-animation: snowanim2 6s linear 1s infinite; \n  animation: snowanim2 6s linear 1s infinite; \n}\n.snow3{\n  -webkit-animation: snowanim3 7s linear 2s infinite; \n  animation: snowanim3 7s linear 2s infinite; \n}\n@-webkit-keyframes snowanim1\n{\n  0% { top:0%;left:50%; }        \n  100% { top:100%;left:65%; }\n}\n@-webkit-keyframes snowanim2\n{\n  0% { top:0%;left:30%; }        \n  100% { top:100%;left:25%; }\n}\n@-webkit-keyframes snowanim3\n{\n  0% { top:0%;left:70%; }        \n  100% { top:100%;left:60%; }\n}\n@keyframes snowanim1\n{\n  0% { top:0%;left:50%; }        \n  100% { top:100%;left:65%; }\n}\n@keyframes snowanim2\n{\n  0% { top:0%;left:30%; }        \n  100% { top:100%;left:25%; }\n}\n@keyframes snowanim3\n{\n  0% { top:0%;left:70%; }        \n  100% { top:100%;left:60%; }\n}\n<\/style>\n<div class=\"animcontainer\">\n<div class=\"snow snow1\"><\/div>\n<div class=\"snow snow2\"><\/div>\n<div class=\"snow snow3\"><\/div>\n<\/div>\n<p><BR><BR><BR><\/p>\n<h4>CSS background image animation<\/h4>\n<p><BR><\/p>\n<p><a href=\"https:\/\/freshinbox.com\/blog\/wp-content\/uploads\/2015\/12\/nest-snow2.gif\"><img decoding=\"async\" src=\"https:\/\/freshinbox.com\/blog\/wp-content\/uploads\/2015\/12\/nest-snow2.gif\" alt=\"nest-snow2\" width=\"379\" class=\"aligncenter size-full wp-image-2435\" \/><\/a><BR><\/p>\n<p>Another snow falling animation technique is vertically animating a CSS background image that has the snowflakes drawn on it. <a href=\"http:\/\/nest.com\" target=_new>Nest<\/a> used this technique on two emails this holiday season. What&#8217;s especially cool is that the Nest email layered three backgrounds with different sizes of snow moving at different speeds giving a 3D feel to it. <\/p>\n<p>Here&#8217;s a simplified version, create a div with the class &#8220;background-container&#8221; and use the CSS below:<\/p>\n<pre class=\"lang:default decode:true \" >.background-container{\r\n  background-image: \r\n    url(red-large.png), \r\n    url(green-med.png), \r\n    url(blue-small.png);\r\n  -webkit-animation: backanim 10s linear infinite; \r\n  background-color:#abe2fe;\r\n  width:80%;\r\n  height:300px;\r\n  overflow:hidden;\r\n}\r\n@-webkit-keyframes backanim\r\n{\r\n  0% { background-position: 0px 0px; }\r\n  100% {\r\n    background-position: \r\n      0 300px, \r\n      0 200px, \r\n      0 100px;\r\n  }\r\n}\r\n<\/pre>\n<style>\n.background-container{\n  background-image: \n    url(https:\/\/freshinbox.com\/blog\/wp-content\/uploads\/2015\/12\/red-large.png), \n    url(https:\/\/freshinbox.com\/blog\/wp-content\/uploads\/2015\/12\/green-med.png), \n    url(https:\/\/freshinbox.com\/blog\/wp-content\/uploads\/2015\/12\/blue-small.png);\n  -webkit-animation: backanim 10s linear infinite; \n  animation: backanim 10s linear infinite; \n  background-color:#abe2fe;\n  width:90%;\n  margin: 0px auto;\n  height:200px;\n  overflow:hidden;\n}\n@-webkit-keyframes backanim\n{\n  0% { background-position: 0px 0px; }\n  100% {\n    background-position: \n      0 300px, \n      0 200px, \n      0 100px;\n  }\n}\n@keyframes backanim\n{\n  0% { background-position: 0px 0px; }\n  100% {\n    background-position: \n      0 300px, \n      0 200px, \n      0 100px;\n  }\n}\n<\/style>\n<p><center><\/p>\n<div style=\"display:inline-block;margin:20px;border:1px solid #888888;\">\n<img decoding=\"async\" src=\"https:\/\/freshinbox.com\/blog\/wp-content\/uploads\/2015\/12\/red-large.png\"  width=\"140\"\/><\/div>\n<div style=\"display:inline-block;margin:20px;border:1px solid #888888;\">\n<img decoding=\"async\" src=\"https:\/\/freshinbox.com\/blog\/wp-content\/uploads\/2015\/12\/green-med.png\"  width=\"140\"\/><\/div>\n<div style=\"display:inline-block;margin:20px;border:1px solid #888888;\">\n<img decoding=\"async\" src=\"https:\/\/freshinbox.com\/blog\/wp-content\/uploads\/2015\/12\/blue-small.png\"  width=\"140\"\/><\/div>\n<p><\/center><\/p>\n<div class=\"background-container\">\n<\/div>\n<p><BR><\/p>\n<p>If you watch closely, you&#8217;d notice that the animation appears to glitch every 10 seconds. This is because after the animation ends, the position of the images are reset. You can mitigate this effect by either making the animation last longer (ie. 30 seconds) so readers are less likely to notice, or calculate at which time the animation will &#8220;meet&#8221; its original position and have the animation reset then.<BR><BR><BR><\/p>\n<h4>Something for the other clients<\/h4>\n<p>Since only webkit based clients support CSS animation, it would be nice if there&#8217;s something for other clients as well. This holiday email below by <a href=\"http:\/\/waxmedia.co.uk\/\" target=_new>Wax Media<\/a> &#8211; the folks who happened to design the B&#038;Q email above &#8211; incorporated a peek-a-boo animated gif owl so those not fortunate enough to experience the animated CSS (background image) stars would also get to see something cool.<\/p>\n<p><a href=\"https:\/\/freshinbox.com\/blog\/wp-content\/uploads\/2015\/12\/wax-snow.gif\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/freshinbox.com\/blog\/wp-content\/uploads\/2015\/12\/wax-snow.gif\" alt=\"wax-snow\" width=\"450\" height=\"360\" class=\"aligncenter size-full wp-image-2448\" \/><\/a><\/p>\n<p><BR><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","protected":false},"excerpt":{"rendered":"<p>Its the holidays and emails take on a certain holiday spirit. Logos take on some holiday cheer, reds and greens are added to the color palette and snow!<BR><BR><\/p>\n<p>This is also the time where falling snow animations are added to emails. In the past this would involve animated gifs, but these days campaigns are incorporating CSS animations to bring that snowfall effect&#8230;<\/p>\n","protected":false},"author":2,"featured_media":2462,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[24,25,47],"tags":[],"_links":{"self":[{"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/posts\/2417"}],"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=2417"}],"version-history":[{"count":54,"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/posts\/2417\/revisions"}],"predecessor-version":[{"id":2697,"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/posts\/2417\/revisions\/2697"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/media\/2462"}],"wp:attachment":[{"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/media?parent=2417"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/categories?post=2417"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/tags?post=2417"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}