{"id":389,"date":"2014-02-25T15:41:55","date_gmt":"2014-02-25T15:41:55","guid":{"rendered":"http:\/\/freshinbox.com\/blog\/?p=389"},"modified":"2015-08-30T02:42:08","modified_gmt":"2015-08-30T02:42:08","slug":"image-carousel-in-email-part-1-mobile","status":"publish","type":"post","link":"https:\/\/freshinbox.com\/blog\/image-carousel-in-email-part-1-mobile\/","title":{"rendered":"How to Create an Image Carousel for Email \u2013 Part 1 [Mobile]"},"content":{"rendered":"<p>This is a two part article that will walk through how to build a thumbnail driven image carousel in an email. In this post we will work on getting it to work on mobile clients &#8211; specifically the native iPhone and Android mail app. In the second post we will add support for non-mobile email clients. <\/p>\n<div style=\"max-width:400px;margin:0 auto;padding:10px;border:1px solid #888888;text-align:center;\">\n<b>Try out the <a href=\"https:\/\/freshinbox.com\/resources\/tools\/carousel\/\">Image Carousel for Email Tool<\/a><\/b><br \/>\nThe tool uses a slightly <a href=\"https:\/\/freshinbox.com\/blog\/image-carousel-for-email-tool\/\">different technique<\/a>\n<\/div>\n<p><BR><\/p>\n<p><strong>Update:<\/strong> <a href=\"https:\/\/freshinbox.com\/blog\/how-to-create-an-image-carousel-for-email-part-2\/\">Part 2 has now been posted!<\/a><\/p>\n<p align=\"center\"><img decoding=\"async\" src=\"https:\/\/freshinbox.com\/blog\/wp-content\/uploads\/2014\/02\/carousel-img.jpg\" alt=\"Image of Carousel Example\" width=300 \/><\/p>\n<p>As you can see from the screenshot above, we&#8217;ll be creating a carousel with thumbnails above the image. Users with email clients that aren\u2019t supported will just see the image without the thumbnails.  <\/p>\n<p>Also this carousel will only allow for a single link \u2013 so this example will work great for multiple views of a product or in this example, views of a room in a hotel or property. This example is not a good fit for featuring multiple different products with each requiring their own link. <\/p>\n<p>This post will build upon some of the techniques we covered in <a href=\"https:\/\/freshinbox.com\/blog\/interactive-images-on-mobile-email\/\">Interactive Images in Mobile Email<\/a> so if this looks confusing, take a look at the earlier article as it is less involved.<BR><BR><\/p>\n<div id=\"email-me\" style=\"margin-left:20px;\">\n  <input type=email id=\"email-me-email\" placeholder=\"Email address\"> <input id=\"email-me-btn\" type=button value=\"Email Me This Example\"><BR>\n<\/div>\n<p><BR><BR><\/p>\n<h4>Preparing the assets<\/h4>\n<p>For this example we\u2019d need the four thumbnail pictures and four regular pictures. Make sure to size the thumbnails so they fit in a single row.<BR><BR><\/p>\n<h4>Main image and link<\/h4>\n<p>First we&#8217;re going to just create a container div that is going to hold our carousel. We&#8217;ll call the class &#8220;car-cont&#8221;. Then we&#8217;ll add the main image with a link and assign the class &#8220;car-img&#8221; to a div wrapping the link and image.  The width and height of the container is set to the width and height of the main image.<\/p>\n<pre class=\"lang:default decode:true \" >&lt;div class=\"car-cont\" style=\"width:350px;height:263px;max-height:263px;\r\n  overflow:hidden;position:relative;\"&gt;\r\n &lt;div class=\"car-img\"&gt;\r\n &lt;a href=\"http:\/\/...\/link \"&gt;\r\n  &lt;img src=\"http:\/\/...\/bed.jpg\" width=\"350\" height=\"263\" \r\n     border=\"0\" alt=\"Hotel\" style=\"display:block;\"&gt;\r\n &lt;\/a&gt;&lt;\/div&gt;\r\n&lt;\/div&gt;<\/pre>\n<p><BR><BR> <\/p>\n<h4>Adding the thumbnails and additional images<\/h4>\n<p>Next we&#8217;ll add the thumbnails along with the additional images. Since the thumbnails would add vertical space and would overflow the container, we&#8217;ll hide the thumbnails and additional images initially using the hiding tricks covered in <a href=\"https:\/\/freshinbox.com\/blog\/bulletproof-solution-to-hiding-mobile-content-when-opened-in-non-mobile-email-clients\/\">this article<\/a>.<\/p>\n<pre class=\"lang:default mark:4-29 decode:true \" >&lt;div class=\"car-cont\" style=\"width:350px;height:263px;max-height:263px;\r\n  overflow:hidden;position:relative;\"&gt;\r\n\r\n&lt;!--[if !mso]&gt;&lt;!-- --&gt;\r\n&lt;div class=\"car-thumb\" style=\"max-height:0px;height:0px;overflow:hidden;\"&gt;\r\n  &lt;img src=\"http:\/\/...\/images\/thumb-bed.jpg\"&gt;\r\n&lt;\/div&gt;\r\n&lt;div class=\"car-thumb\" style=\"max-height:0px; height:0px; overflow: hidden;\"&gt;\r\n  &lt;img src=\"http:\/\/...\/images\/thumb-table.jpg\"&gt;\r\n&lt;\/div&gt;\r\n  &lt;div class=\"car-img\" style=\"max-height:0px;height:0px;overflow:hidden;\"&gt;\r\n  &lt;img src=\"http:\/\/...\/images\/table.jpg\" width=\"350\" height=\"263\" \r\n    border=\"0\" style=\"display:block;\"&gt;\r\n  &lt;\/div&gt;\r\n&lt;div class=\"car-thumb\" style=\"max-height:0px;height:0px;overflow:hidden;\"&gt;\r\n  &lt;img src=\"http:\/\/...\/images\/thumb-pool.jpg\"&gt;\r\n&lt;\/div&gt;\r\n  &lt;div class=\"car-img\" style=\"max-height:0px; height:0px; overflow: hidden;\"&gt;\r\n  &lt;img src=\"http:\/\/...\/images\/pool.jpg\" width=\"350\" height=\"263\" \r\n    border=\"0\" style=\"display:block;\"&gt;\r\n  &lt;\/div&gt;\r\n&lt;div class=\"car-thumb\" style=\"max-height:0px;height:0px;overflow:hidden;\"&gt;\r\n  &lt;img src=\"http:\/\/...\/images\/thumb-balcony.jpg\"&gt;\r\n&lt;\/div&gt;\r\n  &lt;div class=\"car-img\" style=\"max-height:0px;height:0px;overflow:hidden;\"&gt;\r\n  &lt;img src=\"http:\/\/...\/images\/balcony.jpg\" width=\"350\" height=\"263\" \r\n  border=\"0\" style=\"display:block;\"&gt;\r\n  &lt;\/div&gt;\r\n&lt;!--&lt;![endif]--&gt;\r\n\r\n &lt;div class=\"car-img\"&gt;\r\n &lt;a href=\"http:\/\/...\/link\"&gt;\r\n  &lt;img src=\"http:\/\/...\/images\/bed.jpg\" width=\"350\" height=\"263\" border=\"0\" \r\n  alt=\"Hotel\" style=\"display:block;\"&gt;&lt;\/a&gt;\r\n &lt;\/div&gt;\r\n&lt;\/div&gt;<\/pre>\n<p>Notice that except for the first thumbnail (the bed) we interleave thumbnails (car-thumb) with their associated images (car-img).<\/p>\n<p>The reason for this is so that when the user taps a thumbnail (activating the :hover pseudo-class), we can trigger the display of the adjacent image using the CSS sibling selector (&#8220;+&#8221;) (see explanation in <a href=\"https:\/\/freshinbox.com\/blog\/interactive-images-on-mobile-email\/\">this example<\/a>).<\/p>\n<pre class=\"lang:default decode:true \" >.car-thumb:hover + .car-img {...}\r\n<\/pre>\n<p>We leave the main image at the bottom instead of adjacent to the first thumbnail to separate the main image from the rest of the interactive content to make it easier to hide. Also it naturally puts the main image on top by default when we stack the images using absolute  positioning later.<BR><BR><\/p>\n<h4>CSS Styles<\/h4>\n<p>Since this version of the carousel will only be enabled on mobile, we&#8217;ll wrap the whole CSS within a media query<\/p>\n<pre class=\"lang:default decode:true \" >&lt;style&gt;\r\n&nbsp;@media screen and (max-device-width: 1024px) {\r\n    div[class].car-cont{\r\n      height:327px !important;\r\n      max-height:327px !important;\r\n    }\r\n    div[class].car-thumb, div[class].car-thumb img\r\n    {\r\n      display: inline-block;\r\n      max-height: none !important;  \r\n      width:87px;\r\n      height:65px !important;\r\n      cursor: pointer;\r\n    }\r\n    div[class].car-img{\r\n      height: auto !important;\r\n      max-height: none !important;\r\n      position: absolute;\r\n      left:0px;\r\n      top: 65px;    \r\n    }\r\n    div[class].car-thumb:hover + .car-img\r\n    {\r\n      z-index:2;\r\n    }\r\n}\r\n&lt;\/style&gt;\r\n<\/pre>\n<p>Here\u2019s what\u2019s going on:<\/p>\n<p>Firstly, we increase the height of the container to accommodate the thumbnails.<\/p>\n<pre class=\"lang:default decode:true \" >div[class].car-cont{\r\n  height:327px !important;\r\n  max-height:327px !important;\r\n}<\/pre>\n<p>Then, we set the height and width of the thumbnails (car-thumb) as well as set the display to &#8220;inline-block&#8221;, allowing the thumbnails to stack left to right.<\/p>\n<pre class=\"lang:default decode:true \" >div[class].car-thumb, div[class].car-thumb img\r\n{\r\n  display: inline-block;\r\n  max-height: none !important;  \r\n  width:87px;\r\n  height:65px;\r\n}<\/pre>\n<p>Then we set the position of the images to absolute and position them below the thumbnails. The four images now occupy the same space stacked on top of each other with only the last image (the bed) being visible.<\/p>\n<pre class=\"lang:default decode:true \" >div[class].car-img{\r\n  height: auto !important;\r\n  max-height: none !important;\r\n  position: absolute;\r\n  left:0px;\r\n  top: 65px;    \r\n}<\/pre>\n<p>Finally, we use the sibling selector to shift the z-index of an image adjacent to the thumbnail up a notch when the user taps on it so it appears above the main image.<\/p>\n<pre class=\"lang:default decode:true \" >div[class].car-thumb:hover + .car-img\r\n{\r\n  z-index:2;\r\n}\r\n<\/pre>\n<p><BR><BR> <\/p>\n<h4>Takeaway<\/h4>\n<p>This example works on the iPhone and Android (2.3 and 4.0) native email clients. However, mobile app and mobile web clients of Yahoo! Mail, Outlook.com or Gmail will only  display the main image without the thumbnails.<\/p>\n<p>As you can see building an image carousel for mobile email is pretty straightforward. To make the carousel work for web clients and Outlook 2003, we\u2019ll have to work a little harder. <\/p>\n<p><a href=\"https:\/\/freshinbox.com\/blog\/how-to-create-an-image-carousel-for-email-part-2\/\">Click here to read Part 2&#8230;<\/a><\/p>\n<style>\n#email-me {\n  padding:10px 10px;\n  font-family: \"Lucida Grande\";<\/p>\n<p>}\n#email-me-email {\n  width:170px;\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;<\/p>\n<p>}\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;<\/p>\n<p>}\n#email-me-btn:hover {\n  background-color: #78D62C;\n}\n#email-me{\n  width: 400px;\n  padding:20px;\n  border:3px solid #888888;\n  border-radius: 5px;\n}\n<\/style>\n<p><BR><\/p>\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\/carousel\/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>This is a two part article that will walk through how to build a thumbnail driven image carousel in an email. In this post we will work on getting it to work on mobile clients &#8211; specifically the native iPhone and Android mail app&#8230;<\/p>\n","protected":false},"author":2,"featured_media":422,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[28,24,25],"tags":[8,11,44,10,5,16,43,9,4,14,34,40,15,13],"_links":{"self":[{"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/posts\/389"}],"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=389"}],"version-history":[{"count":40,"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/posts\/389\/revisions"}],"predecessor-version":[{"id":2144,"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/posts\/389\/revisions\/2144"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/media\/422"}],"wp:attachment":[{"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/media?parent=389"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/categories?post=389"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/tags?post=389"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}