
Before and After Slider in Email
Hey Community,
I recently built a before/after slider for an email and I had to share it with everyone! You can check out the codepen here or check out the scope
The code's still pretty messy and could use some clean-up so some things might seem repetitive/unneccessary. Within the email there are two before/after sliders, one for desktop and one for mobile. Because I could use CSS3 transitions I re-made it for mobile to give it that smooth scroll instead of the snapping you see on desktop. The slider functions using a nested table with two <td>'s. The first <td> has a background image which is the before image. The parent table has a background image of the after image. To be able to have a slider that can go back and forth you can only assign width="50%" to the second <td>. If you assign a width to the first <td> the second <td> will be unable to overwrite the first <td>'s width.
Using [lang~="after"]:hover {width:100%}
and [lang~="before"]:hover{width:100%}
(thank you fresh inbox!) we can change the widths of the two <td>'s which will reveal the background image creating that before/after effect.
It currently works in the following:
- Gmail
- Outlook.com
- Yahoo Mail
- iOS
- Android Native
I have a pretty limited library of devices so if you find something it doesn't work on let me know in the comments.
I plan on doing a more in-depth write-up when I find time but I couldn't wait that long to post the final result!
I tried to see if I could use this technique today, but no luck. Even if I copied the whole email code unmodified (as found after clicking the scope link), it does not seem to work in the first three email clients I tried:
I would be interested if anybody was able to use this recently.
Pavel
This is a really nice form of email interactivity! What if you wanted to make the top section, where the effect is, a link? It's a large piece of potentially clickable real-estate in an email, and I know where ever I've worked, everyone wants that top banner clickable.
The best I can think of currently is adding links to the Before/After labels. You could wrap the containing table in an <a> tag but that only works in some email clients.
Wow. Beautifully done!!! Nice work!
Wow awesome, thanks for sharing! I can't wait to play around with it later :)
Wow, great job Austin. Very cool email.