{"id":4844,"date":"2018-01-03T08:26:28","date_gmt":"2018-01-03T08:26:28","guid":{"rendered":"http:\/\/a1webdesignteam.com\/blog\/?p=4844"},"modified":"2018-01-03T08:26:28","modified_gmt":"2018-01-03T08:26:28","slug":"elastislide-a-responsive-jquery-carousel-slider","status":"publish","type":"post","link":"https:\/\/a1webdesignteam.com\/blog\/elastislide-a-responsive-jquery-carousel-slider\/","title":{"rendered":"Elastislide \u2013 A Responsive jQuery Carousel Slider"},"content":{"rendered":"<div class=\"ct-post-excerpt\">Elastislide is a responsive image carousel that will adapt fluidly in a layout. It is a jQuery plugin that can be laid out horizontally or vertically with a pre-defined minimum number of shown images.<\/div>\n<div class=\"ct-ad-article-wrapper\">\n<div class=\"ct-ad-article\">\n<div id=\"bsap_1277316\" class=\"bsap bsap_1277316\" data-serve=\"CKYDK5T\"><a class=\"demo\" href=\"http:\/\/tympanus.net\/Development\/Elastislide\/\" target=\"_blank\" rel=\"noopener\">View demo<\/a> <a class=\"download\" href=\"http:\/\/tympanus.net\/Development\/Elastislide\/Elastislide.zip\">Download source<\/a><\/div>\n<\/div>\n<\/div>\n<p>With the responsive awakening in web design it becomes important to not only take care of the visual part of a website but also of the functionality. Elastislide is a responsive jQuery image carousel that will adapt its size and its behavior in order to work on any screen size. Inserting the carousel\u2019s structure into a container with a fluid width will also make the carousel fluid.<\/p>\n<p>In a carousel, one could think that simply making its container \u201cshorter\u201d will solve the problem on smaller screens, but in some cases (e.g. when we have bigger images) it might be reasonable to resize the items as well. This and other options are part of Elastislide\u2019s properties.<\/p>\n<p>Elastislide uses the jQuery++ for the swipe events on touch devices.<\/p>\n<div class=\"ct-ad-article-wrapper ct-ad-article-wrapper-in\">\n<div class=\"ct-ad-article\">The beautiful images are by talented Sherman Geronimo-Tan and they are licensed under Creative Commons Attribution 2.0 Generic (CC BY 2.0).<\/div>\n<\/div>\n<h3>The HTML Structure<\/h3>\n<p>When using the plugin, you\u2019ll simply have to apply it to an unordered list with images (optionally with anchors). Make sure the surrounding container is fluid, i.e. has a percentage-based width. (If you put the carousel in a container with a fixed width, it will not adapt. So make sure that your container has a fluid layout.)<\/p>\n<pre class=\"brush:xml hljs xml\"><span class=\"hljs-tag\">&lt;<span class=\"hljs-title\">ul<\/span> <span class=\"hljs-attribute\">id<\/span>=<span class=\"hljs-value\">\"carousel\"<\/span> <span class=\"hljs-attribute\">class<\/span>=<span class=\"hljs-value\">\"elastislide-list\"<\/span>&gt;<\/span>\r\n\t<span class=\"hljs-tag\">&lt;<span class=\"hljs-title\">li<\/span>&gt;<\/span><span class=\"hljs-tag\">&lt;<span class=\"hljs-title\">a<\/span> <span class=\"hljs-attribute\">href<\/span>=<span class=\"hljs-value\">\"#\"<\/span>&gt;<\/span><span class=\"hljs-tag\">&lt;<span class=\"hljs-title\">img<\/span> <span class=\"hljs-attribute\">src<\/span>=<span class=\"hljs-value\">\"images\/1.jpg\"<\/span> <span class=\"hljs-attribute\">alt<\/span>=<span class=\"hljs-value\">\"image01\"<\/span> \/&gt;<\/span><span class=\"hljs-tag\">&lt;\/<span class=\"hljs-title\">a<\/span>&gt;<\/span><span class=\"hljs-tag\">&lt;\/<span class=\"hljs-title\">li<\/span>&gt;<\/span>\r\n\t<span class=\"hljs-tag\">&lt;<span class=\"hljs-title\">li<\/span>&gt;<\/span><span class=\"hljs-tag\">&lt;<span class=\"hljs-title\">a<\/span> <span class=\"hljs-attribute\">href<\/span>=<span class=\"hljs-value\">\"#\"<\/span>&gt;<\/span><span class=\"hljs-tag\">&lt;<span class=\"hljs-title\">img<\/span> <span class=\"hljs-attribute\">src<\/span>=<span class=\"hljs-value\">\"images\/2.jpg\"<\/span> <span class=\"hljs-attribute\">alt<\/span>=<span class=\"hljs-value\">\"image02\"<\/span> \/&gt;<\/span><span class=\"hljs-tag\">&lt;\/<span class=\"hljs-title\">a<\/span>&gt;<\/span><span class=\"hljs-tag\">&lt;\/<span class=\"hljs-title\">li<\/span>&gt;<\/span>\r\n\t<span class=\"hljs-tag\">&lt;<span class=\"hljs-title\">li<\/span>&gt;<\/span><span class=\"hljs-tag\">&lt;<span class=\"hljs-title\">a<\/span> <span class=\"hljs-attribute\">href<\/span>=<span class=\"hljs-value\">\"#\"<\/span>&gt;<\/span><span class=\"hljs-tag\">&lt;<span class=\"hljs-title\">img<\/span> <span class=\"hljs-attribute\">src<\/span>=<span class=\"hljs-value\">\"images\/3.jpg\"<\/span> <span class=\"hljs-attribute\">alt<\/span>=<span class=\"hljs-value\">\"image03\"<\/span> \/&gt;<\/span><span class=\"hljs-tag\">&lt;\/<span class=\"hljs-title\">a<\/span>&gt;<\/span><span class=\"hljs-tag\">&lt;\/<span class=\"hljs-title\">li<\/span>&gt;<\/span>\r\n\t<span class=\"hljs-comment\">&lt;!-- ... --&gt;<\/span>\r\n<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-title\">ul<\/span>&gt;<\/span>\r\n<\/pre>\n<p>Use your preferred ID and call the plugin like this:<\/p>\n<pre class=\"brush:js hljs javascript\">$(<span class=\"hljs-string\">'#carousel'<\/span>).elastislide();\r\n<\/pre>\n<h3>Options<\/h3>\n<p>Elastislide has the following default options:<\/p>\n<pre class=\"brush:js hljs javascript\">$.Elastislide.defaults = {\r\n\t<span class=\"hljs-comment\">\/\/ orientation 'horizontal' || 'vertical'<\/span>\r\n\torientation : <span class=\"hljs-string\">'horizontal'<\/span>,\r\n\r\n\t<span class=\"hljs-comment\">\/\/ sliding speed<\/span>\r\n\tspeed : <span class=\"hljs-number\">500<\/span>,\r\n\r\n\t<span class=\"hljs-comment\">\/\/ sliding easing<\/span>\r\n\teasing : <span class=\"hljs-string\">'ease-in-out'<\/span>,\r\n\r\n\t<span class=\"hljs-comment\">\/\/ the minimum number of items to show. <\/span>\r\n\t<span class=\"hljs-comment\">\/\/ when we resize the window, this will make sure minItems are always shown <\/span>\r\n\t<span class=\"hljs-comment\">\/\/ (unless of course minItems is higher than the total number of elements)<\/span>\r\n\tminItems : <span class=\"hljs-number\">3<\/span>,\r\n\r\n\t<span class=\"hljs-comment\">\/\/ index of the current item (left most item of the carousel)<\/span>\r\n\tstart : <span class=\"hljs-number\">0<\/span>,\r\n\t\r\n\t<span class=\"hljs-comment\">\/\/ click item callback<\/span>\r\n\tonClick : <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span><span class=\"hljs-params\">( el, position, evt )<\/span> <\/span>{ <span class=\"hljs-keyword\">return<\/span> <span class=\"hljs-literal\">false<\/span>; },\r\n\tonReady : <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span><span class=\"hljs-params\">()<\/span> <\/span>{ <span class=\"hljs-keyword\">return<\/span> <span class=\"hljs-literal\">false<\/span>; },\r\n\tonBeforeSlide : <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span><span class=\"hljs-params\">()<\/span> <\/span>{ <span class=\"hljs-keyword\">return<\/span> <span class=\"hljs-literal\">false<\/span>; },\r\n\tonAfterSlide : <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span><span class=\"hljs-params\">()<\/span> <\/span>{ <span class=\"hljs-keyword\">return<\/span> <span class=\"hljs-literal\">false<\/span>; }\r\n};\r\n<\/pre>\n<p>It is also possible to dynamically add new items to the carousel. The following is an example on how to achieve that:<\/p>\n<pre class=\"brush:js hljs javascript\"><span class=\"hljs-keyword\">var<\/span> carousel = $(<span class=\"hljs-string\">'#carousel'<\/span>).elastislide();\r\n...\r\n\r\n$(<span class=\"hljs-string\">'#carousel'<\/span>).append(<span class=\"hljs-string\">\"&lt;li&gt;&lt;a href=\"<\/span>#<span class=\"hljs-string\">\"&gt;&lt;img src=\"<\/span>images\/<span class=\"hljs-number\">10.<\/span>jpg<span class=\"hljs-string\">\" alt=\"<\/span>image03<span class=\"hljs-string\">\" \/&gt;&lt;\/a&gt;&lt;\/li&gt;\"<\/span>);\r\ncarousel.add();\r\n\r\n<\/pre>\n<p>Note that if you use the Elastislide for a vertical layout, the height of the container will be automatically set according to how many images you choose to be visible.<\/p>\n<p><em>This works down to IE8, but if you\u2019d like to use it in IE8 you\u2019ll need to add comments in your list in order to prevent white spaces.<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Elastislide is a responsive image carousel that will adapt fluidly in a layout. It is a jQuery plugin that can be laid out horizontally or vertically with a pre-defined minimum number of shown images. View demo Download source With the responsive awakening in web design it becomes important to not only take care of the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":4846,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0},"categories":[6],"tags":[51],"_links":{"self":[{"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/posts\/4844"}],"collection":[{"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/comments?post=4844"}],"version-history":[{"count":0,"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/posts\/4844\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/media\/4846"}],"wp:attachment":[{"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/media?parent=4844"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/categories?post=4844"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/tags?post=4844"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}