Monday, November 27, 2023
HomeEmail MarketingEasy methods to Add a Snow Impact to an E-mail Utilizing CSS...

Easy methods to Add a Snow Impact to an E-mail Utilizing CSS Animation


css animation with snowflakes

Inboxes are all the time jammed up with vacation emails – there’s a whole lot of competitors. So, how will you make your e-mail advertising campaigns stand out from the remainder? Strive including a little bit of vacation cheer to your common emails by creating some animated snow utilizing CSS.

Right here’s what the impact seems like on a latest E-mail on Acid publication:

Email on Acid newsletter with snow effect

Setting Up the CSS Animation

The snow impact is actually a snowflake or form in a div that you simply animate utilizing CSS. This system strikes the picture from the highest to the underside of a container div you place round your e-mail tables.

CSS animations work on a variety of e-mail shoppers together with iOS, Apple Mail, Android Native Mail and Outlook for Mac – take a look at the E-mail on Acid final information to CSS animation for extra data. The snow animation gained’t show on different e-mail shoppers, so that you don’t want to supply a fallback.

First, we arrange the media question to detect the webkit, that may help the CSS animation.

@media display and (-webkit-min-device-pixel-ratio: 0) {
}

Subsequent, we arrange the container the snow will probably be in.

.snowcontainer{
  place:relative;
  width:100%;
  overflow:seen;
}

We then have to outline the snow. The best means to do that is to make use of a form that doesn’t want a picture, corresponding to a sq.. You possibly can create a sq. by setting top: 18px by width: 18px and setting a border-radius that’s half the peak (to realize an ideal circle), border-radius: 9px. Set the place:absolute  so the snow will probably be positioned throughout the container and prime: -20px to start out the animation earlier than it enters the snowcontainer. Lastly, add a background-color to set the colour of the form.

It seems like this:

shape snowflake

Right here’s the code for the form snowflake:

.snow{
            top: 18px;
            border-radius: 9px;
            width: 18px;
            place: absolute;
            prime: -20px;
            background-color: #ffffff;
      }

One other means so as to add a snowflake is so as to add a background picture. This system is just like to the sq. approach above, but it surely makes use of a background-image and no border-radius. With these adjustments, the snowflake will appear as if this:

snowflake image

Right here’s the code for the picture snowflake:

.snowimage{
  /* dimension of picture */
  top:18px;
  width:18px;
  /* absolute - relative to the container div */
  place:absolute;
  /* The place animation begins */
  prime:-20px;
  /* picture hyperlink */
  background-image:url('photos/snowflake.png');
}

Setting the background-image as a .png means the snowflake may have a clear background and present the content material by it. If you happen to want some snowflake inspiration, take a look at the Noun Undertaking’s snowflake icons.

With the code as is, we simply have some shapes inside a <div>. To animate them, we will put collectively a shortened model of an animation. See under:

.snow1{
  animation: snow1 5s linear 0s infinite;
 }
 /* animation: Title of animation / size of animation / timing operate 
(linear = similar velocity from starting to finish) / delay (time between 
animation finish and begin) / variety of instances */

This animation known as snow1. We outline the size of the animation as 5s (5 seconds) and the linear timing operate. The linear timing quantity retains the animation the identical velocity all through – 0s (zero seconds) is the delay earlier than the animation begins once more. Lastly, we embrace the variety of instances the animation will run (infinite).

By creating a number of completely different animations with barely completely different lengths and delay time, the snow will fall at random.

.snow2{
  animation: snow2 6s linear 1s infinite;
 }
 .snow3{
  animation: snow3 7s linear 2s infinite;
 }

Subsequent, we arrange the keyframe animations to dictate the place the snowflake will transfer to and from.

@keyframes snow1
 {
  0% { prime:0%;left:50%; }
  100% { prime:100%;left:65%; }
 }

In the beginning of the animation (0%), we place the snowflake on the prime of the div (0%) and 50% from the left. On the finish of the animation (100%) the snowflake is 100% from the highest and 65% from the left.

By setting the beginning and finish factors barely completely different in every animation, the snow will appear to seem extra at random.

@keyframes snow2
 {
  0% { prime:0%;left:30%; }
  100% { prime:100%;left:25%; }
 }
 @keyframes snow3
 {
  0% { prime:0%;left:70%; }
  100% { prime:100%;left:60%; }
 }

snowflake animation

The HTML for the Snowflake Animation

When you’ve created the CSS animation, you’ll want so as to add this impact to your e-mail utilizing HTML. To create this animation approach, the primary little bit of HTML you want is a <div> to open the snow container. You possibly can set the peak and width of the container to determine the place the snow will present. For instance:

<div class="snowcontainer" type="width: 100%; top: 500px;">

Subsequent, every particular person snowdrop must be set. To do that, begin with a <div> with the category of the snowimage or snow as arrange in your CSS. Observe that with the identify of the animation (e.g. snow1). The code ought to appear to be this:

<div class="snowimage snow1"></div>

Then, add in all of the snowdrops and animations throughout the snow container. See under:

<div class="snowcontainer" type="top: 500px;">
  <div class="snowimage snow1"></div>
  <div class="snow snow2"></div>
  <div class="snow snow3"></div>

Place all of your e-mail content material you desire to under your snowdrops and end with a closing </div> to finish the snowcontainer.

To see the snow in motion, take a look at the complete code right here.

Present Us What You’ve Obtained!

Have you ever tried this animation in one in every of your vacation emails? Tell us the way it went or, higher but, present us! Share your expertise within the feedback part under or attain out on Fb or Twitter.



Writer: Jay Oram

Jay Oram is a part of the design and code options crew on the e-mail specialist company, ActionRocket. In his function at ActionRocket, Jay is normally experimenting with new code for emails or discovering that elusive rendering repair. See extra articles from Jay at emaildesignreview.com or discover him on Twitter at @emailjay_.

Writer: Jay Oram

Jay Oram is a part of the design and code options crew on the e-mail specialist company, ActionRocket. In his function at ActionRocket, Jay is normally experimenting with new code for emails or discovering that elusive rendering repair. See extra articles from Jay at emaildesignreview.com or discover him on Twitter at @emailjay_.



RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments