{"id":3431,"date":"2017-04-12T07:46:17","date_gmt":"2017-04-12T11:46:17","guid":{"rendered":"https:\/\/www.searchenginegenie.com\/web-design-blog\/?p=3431"},"modified":"2017-04-12T07:46:17","modified_gmt":"2017-04-12T11:46:17","slug":"how-to-code-a-rotating-image-slideshow-wcss3-and-jquery","status":"publish","type":"post","link":"https:\/\/www.searchenginegenie.com\/web-design-blog\/how-to-code-a-rotating-image-slideshow-wcss3-and-jquery\/","title":{"rendered":"How  to code a Rotating image slideshow w\/css3 and jquery"},"content":{"rendered":"<h3><strong>Step:1<\/strong><\/h3>\n<p>First we are going to lay down the Html markup of the slideshow. <em>#slideShowContainer<\/em> div is the main container element which holds the <em>#slideShow<\/em> div.<\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #ff0000;\">&lt;!DOCTYPE html&gt;<\/span><\/p>\n<p><span style=\"color: #ff0000;\">&lt;html&gt;<\/span><\/p>\n<p><span style=\"color: #ff0000;\">&lt;head&gt;<\/span><\/p>\n<p><span style=\"color: #ff0000;\">&lt;meta http-equiv=&#8221;Content-Type&#8221; content=&#8221;text\/html; charset=utf-8\u2033 \/&gt;<\/span><\/p>\n<p><span style=\"color: #ff0000;\">&lt;title&gt;Rotating Slideshow With jQuery and CSS3 | Tutorialzine Demo&lt;\/title&gt;<\/span><\/p>\n<p><span style=\"color: #ff0000;\">&lt;link rel=&#8221;stylesheet&#8221; type=&#8221;text\/css&#8221; href=&#8221;css\/styles.css&#8221; \/&gt;<\/span><\/p>\n<p><span style=\"color: #ff0000;\">&lt;\/head&gt;<\/span><\/p>\n<p><span style=\"color: #ff0000;\">&lt;body&gt;<\/span><\/p>\n<p><span style=\"color: #ff0000;\">&lt;div id=&#8221;slideShowContainer&#8221;&gt;<\/span><\/p>\n<p><span style=\"color: #ff0000;\">&lt;div id=&#8221;slideShow&#8221;&gt;<\/span><\/p>\n<p><span style=\"color: #ff0000;\">&lt;ul&gt;<\/span><\/p>\n<p><span style=\"color: #ff0000;\">&lt;li&gt;&lt;img src=&#8221;img\/photos\/1.jpg&#8221; width=&#8221;100%&#8221; alt=&#8221;Fish&#8221; \/&gt;&lt;\/li&gt;<\/span><\/p>\n<p><span style=\"color: #ff0000;\">&lt;li&gt;&lt;img src=&#8221;img\/photos\/2.jpg&#8221; width=&#8221;100%&#8221; alt=&#8221;Ancient&#8221; \/&gt;&lt;\/li&gt;<\/span><\/p>\n<p><span style=\"color: #ff0000;\">&lt;li&gt;&lt;img src=&#8221;img\/photos\/3.jpg&#8221; width=&#8221;100%&#8221; alt=&#8221;Industry&#8221; \/&gt;&lt;\/li&gt;<\/span><\/p>\n<p><span style=\"color: #ff0000;\">&lt;li&gt;&lt;img src=&#8221;img\/photos\/4.jpg&#8221; width=&#8221;100%&#8221; alt=&#8221;Rain&#8221; \/&gt;&lt;\/li&gt;<\/span><\/p>\n<p><span style=\"color: #ff0000;\">&lt;\/ul&gt;<\/span><\/p>\n<p><span style=\"color: #ff0000;\">&lt;\/div&gt;<\/span><\/p>\n<p><span style=\"color: #ff0000;\">&lt;a id=&#8221;previousLink&#8221; href=&#8221;#&#8221;&gt;\u00bb&lt;\/a&gt;<\/span><\/p>\n<p><span style=\"color: #ff0000;\">&lt;a id=&#8221;nextLink&#8221; href=&#8221;#&#8221;&gt;\u00ab&lt;\/a&gt;<\/span><\/p>\n<p><span style=\"color: #ff0000;\">&lt;\/div&gt;<\/span><\/p>\n<p><span style=\"color: #ff0000;\">&lt;script src=&#8221;<a style=\"color: #ff0000;\" href=\"https:\/\/ajax.googleapis.com\/ajax\/libs\/jquery\/1.4.4\/jquery.min.js\">https:\/\/ajax.googleapis.com\/ajax\/libs\/jquery\/1.4.4\/jquery.min.js<\/a>&#8220;&gt;&lt;\/script&gt;<\/span><\/p>\n<p><span style=\"color: #ff0000;\">&lt;script src=&#8221;js\/jquery.rotate.js&#8221;&gt;&lt;\/script&gt;<\/span><\/p>\n<p><span style=\"color: #ff0000;\">&lt;script src=&#8221;js\/script.js&#8221;&gt;&lt;\/script&gt;<\/span><\/p>\n<p><span style=\"color: #ff0000;\">&lt;\/body&gt;<\/span><\/p>\n<p><span style=\"color: #ff0000;\">&lt;\/html&gt;<\/span><\/p>\n<p>&nbsp;<\/p>\n<p>We included the jQuery library, our own script script.js file and the jquery rotate plugin.<\/p>\n<p>&nbsp;<\/p>\n<h3>Step:2<\/h3>\n<p>We can see the styling of the slideshow below:<\/p>\n<p>&nbsp;<\/p>\n<figure id=\"attachment_3435\" aria-describedby=\"caption-attachment-3435\" style=\"width: 300px\" class=\"wp-caption alignnone\"><a name=\"imageclose-3432\"><div class=\"lb-album\"><a href=\"#image-3432\"><img src=\"https:\/\/www.searchenginegenie.com\/web-design-blog\/wp-content\/uploads\/2017\/04\/image-300x234.jpg\" alt=\"rotate\" class=\"wp-image-3435 size-medium\"><span><\/span><\/a><\/div>              \r\n<a href=\"#imageclose-3432\" class=\"css3lightbox-close\">\r\n\t\t\t\t   <div class=\"lb-overlay\" id=\"image-3432\">\r\n                   <img src=\"https:\/\/www.searchenginegenie.com\/web-design-blog\/wp-content\/uploads\/2017\/04\/image.jpg\" alt=\"image-3432\">\r\n                   <\/div><\/a><figcaption id=\"caption-attachment-3435\" class=\"wp-caption-text\">Rotating Slideshow<\/figcaption><\/figure>\n<p>&nbsp;<\/p>\n<h3>Step:3<\/h3>\n<p>Now iam using the jQuery rotate Plugin as it integrates with the animate( ) and css () methods of the library. we are using using jQuery\u2019s<strong><em>.<\/em><\/strong><em>$.Support<\/em> object to test whether the visitor\u2019s browser supports CSS3 transformations.<\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #0000ff;\"><strong>Script.js-part1<\/strong><\/span><\/p>\n<p><span style=\"color: #339966;\">#slideShowContainer{<\/span><br \/>\n<span style=\"color: #339966;\"> width:510px;<\/span><br \/>\n<span style=\"color: #339966;\"> height:510px;<\/span><br \/>\n<span style=\"color: #339966;\"> position:relative;<\/span><br \/>\n<span style=\"color: #339966;\"> margin:120px auto 50px;<\/span><br \/>\n<span style=\"color: #339966;\"> }<\/span><\/p>\n<p><span style=\"color: #339966;\">#slideShow{<\/span><br \/>\n<span style=\"color: #339966;\"> position:absolute;<\/span><br \/>\n<span style=\"color: #339966;\"> height:490px;<\/span><br \/>\n<span style=\"color: #339966;\"> width:490px;<\/span><br \/>\n<span style=\"color: #339966;\"> background-color:#fff;<\/span><br \/>\n<span style=\"color: #339966;\"> margin:10px 0 0 10px;<\/span><br \/>\n<span style=\"color: #339966;\"> z-index:100;<\/span><\/p>\n<p><span style=\"color: #339966;\">-moz-box-shadow:0 0 10px #111;<\/span><br \/>\n<span style=\"color: #339966;\"> -webkit-box-shadow:0 0 10px #111;<\/span><br \/>\n<span style=\"color: #339966;\"> box-shadow:0 0 10px #111;<\/span><br \/>\n<span style=\"color: #339966;\"> }<\/span><\/p>\n<p><span style=\"color: #339966;\">#slideShow ul{<\/span><br \/>\n<span style=\"color: #339966;\"> position:absolute;<\/span><br \/>\n<span style=\"color: #339966;\"> top:15px;<\/span><br \/>\n<span style=\"color: #339966;\"> right:15px;<\/span><br \/>\n<span style=\"color: #339966;\"> bottom:15px;<\/span><br \/>\n<span style=\"color: #339966;\"> left:15px;<\/span><br \/>\n<span style=\"color: #339966;\"> list-style:none;<\/span><br \/>\n<span style=\"color: #339966;\"> overflow:hidden;<\/span><br \/>\n<span style=\"color: #339966;\"> }<\/span><\/p>\n<p><span style=\"color: #339966;\">#slideShow li{<\/span><br \/>\n<span style=\"color: #339966;\"> position:absolute;<\/span><br \/>\n<span style=\"color: #339966;\"> top:0;<\/span><br \/>\n<span style=\"color: #339966;\"> left:0;<\/span><br \/>\n<span style=\"color: #339966;\"> width:100%;<\/span><br \/>\n<span style=\"color: #339966;\"> height:100%;<\/span><br \/>\n<span style=\"color: #339966;\"> }<\/span><\/p>\n<p><span style=\"color: #339966;\">#slideShowContainer &gt; a{<\/span><br \/>\n<span style=\"color: #339966;\"> border:none;<\/span><br \/>\n<span style=\"color: #339966;\"> text-decoration:none;<\/span><br \/>\n<span style=\"color: #339966;\"> text-indent:-99999px;<\/span><br \/>\n<span style=\"color: #339966;\"> overflow:hidden;<\/span><br \/>\n<span style=\"color: #339966;\"> width:36px;<\/span><br \/>\n<span style=\"color: #339966;\"> height:37px;<\/span><br \/>\n<span style=\"color: #339966;\"> background:url(&#8216;..\/img\/arrows.png&#8217;) no-repeat;<\/span><br \/>\n<span style=\"color: #339966;\"> position:absolute;<\/span><br \/>\n<span style=\"color: #339966;\"> top:50%;<\/span><br \/>\n<span style=\"color: #339966;\"> margin-top:-21px;<\/span><br \/>\n<span style=\"color: #339966;\"> }<\/span><\/p>\n<p><span style=\"color: #339966;\">#previousLink{<\/span><br \/>\n<span style=\"color: #339966;\"> left:-38px;<\/span><br \/>\n<span style=\"color: #339966;\"> }<\/span><\/p>\n<p><span style=\"color: #339966;\">#previousLink:hover{<\/span><br \/>\n<span style=\"color: #339966;\"> background-position:bottom left;<\/span><br \/>\n<span style=\"color: #339966;\"> }<\/span><\/p>\n<p><span style=\"color: #339966;\">a#nextLink{<\/span><br \/>\n<span style=\"color: #339966;\"> right:-38px;<\/span><br \/>\n<span style=\"color: #339966;\"> background-position:top right;<\/span><br \/>\n<span style=\"color: #339966;\"> }<\/span><\/p>\n<p><span style=\"color: #339966;\">#nextLink:hover{<\/span><br \/>\n<span style=\"color: #339966;\"> background-position:bottom right;<\/span><br \/>\n<span style=\"color: #339966;\"> }<\/span><\/p>\n<p>&nbsp;<\/p>\n<h3>Step:4<\/h3>\n<p>In second part, the fragment that is executed only in browsers that do not\u00a0 support css3 transformations.The most important is update z-index( ),as otherwise the slides would be displayed in reverse order.<\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #0000ff;\"><strong>Script.js-part2<\/strong><\/span><\/p>\n<p><span style=\"color: #339966;\">$(document).ready(function(){<\/span><\/p>\n<p><span style=\"color: #339966;\">var slideShow = $(&#8216;#slideShow&#8217;),<\/span><br \/>\n<span style=\"color: #339966;\"> ul = slideShow.find(&#8216;ul&#8217;),<\/span><br \/>\n<span style=\"color: #339966;\"> li = ul.find(&#8216;li&#8217;),<\/span><br \/>\n<span style=\"color: #339966;\"> cnt = li.length;<\/span><\/p>\n<p><span style=\"color: #339966;\">\/\/ As the images are positioned absolutely, the last image will be shown on top.<\/span><br \/>\n<span style=\"color: #339966;\"> \/\/ This is why we force them in the correct order by assigning z-indexes:<\/span><\/p>\n<p><span style=\"color: #339966;\">updateZindex();<\/span><\/p>\n<p><span style=\"color: #339966;\">if($.support.transform){<\/span><\/p>\n<p><span style=\"color: #339966;\">\/\/ Modern browsers with support for css3 transformations<\/span><\/p>\n<p><span style=\"color: #339966;\">li.find(&#8216;img&#8217;).css(&#8216;rotate&#8217;,function(i){<\/span><br \/>\n<span style=\"color: #339966;\"> \/\/ Rotating the images counter-clockwise<\/span><br \/>\n<span style=\"color: #339966;\"> return (-90*i) + &#8216;deg&#8217;;<\/span><br \/>\n<span style=\"color: #339966;\"> });<\/span><\/p>\n<p><span style=\"color: #339966;\">\/\/ Binding a custom event. the direction and degrees parameters<\/span><br \/>\n<span style=\"color: #339966;\"> \/\/ are passed when the event is triggered later on in the code.<\/span><\/p>\n<p><span style=\"color: #339966;\">slideShow.bind(&#8216;rotateContainer&#8217;,function(e,direction,degrees){<\/span><\/p>\n<p><span style=\"color: #339966;\">\/\/ Zooming in the slideshow:<\/span><\/p>\n<p><span style=\"color: #339966;\">slideShow.animate({<\/span><br \/>\n<span style=\"color: #339966;\"> width\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0: 510,<\/span><br \/>\n<span style=\"color: #339966;\"> height\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0: 510,<\/span><br \/>\n<span style=\"color: #339966;\"> marginTop\u00a0\u00a0 \u00a0: 0,<\/span><br \/>\n<span style=\"color: #339966;\"> marginLeft\u00a0\u00a0 \u00a0: 0<\/span><br \/>\n<span style=\"color: #339966;\"> },&#8217;fast&#8217;,function(){<\/span><\/p>\n<p><span style=\"color: #339966;\">if(direction == &#8216;next&#8217;){<\/span><\/p>\n<p><span style=\"color: #339966;\">\/\/ Moving the topmost image containing Li at<\/span><br \/>\n<span style=\"color: #339966;\"> \/\/ the bottom after a fadeOut animation<\/span><\/p>\n<p><span style=\"color: #339966;\">$(&#8216;li:first&#8217;).fadeOut(&#8216;slow&#8217;,function(){<\/span><br \/>\n<span style=\"color: #339966;\"> $(this).remove().appendTo(ul).show();<\/span><br \/>\n<span style=\"color: #339966;\"> updateZindex();<\/span><br \/>\n<span style=\"color: #339966;\"> });<\/span><br \/>\n<span style=\"color: #339966;\"> }<\/span><br \/>\n<span style=\"color: #339966;\"> else {<\/span><\/p>\n<p><span style=\"color: #339966;\">\/\/ Showing the bottommost Li element on top<\/span><br \/>\n<span style=\"color: #339966;\"> \/\/ with a fade in animation. Notice that we are<\/span><br \/>\n<span style=\"color: #339966;\"> \/\/ updating the z-indexes.<\/span><\/p>\n<p><span style=\"color: #339966;\">var liLast = $(&#8216;li:last&#8217;).hide().remove().prependTo(ul);<\/span><br \/>\n<span style=\"color: #339966;\"> updateZindex();<\/span><br \/>\n<span style=\"color: #339966;\"> liLast.fadeIn(&#8216;slow&#8217;);<\/span><br \/>\n<span style=\"color: #339966;\"> }<\/span><\/p>\n<p><span style=\"color: #339966;\">\/\/ Rotating the slideShow. css(&#8216;rotate&#8217;) gives us the<\/span><br \/>\n<span style=\"color: #339966;\"> \/\/ current rotation in radians. We are converting it to<\/span><br \/>\n<span style=\"color: #339966;\"> \/\/ degrees so we can add +90 or -90.<\/span><\/p>\n<p><span style=\"color: #339966;\">slideShow.animate({<\/span><br \/>\n<span style=\"color: #339966;\"> rotate:Math.round($.rotate.radToDeg(slideShow.css(&#8216;rotate&#8217;))+degrees) + &#8216;deg&#8217;<\/span><br \/>\n<span style=\"color: #339966;\"> },&#8217;slow&#8217;).animate({<\/span><br \/>\n<span style=\"color: #339966;\"> width\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0: 490,<\/span><br \/>\n<span style=\"color: #339966;\"> height\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0: 490,<\/span><br \/>\n<span style=\"color: #339966;\"> marginTop\u00a0\u00a0 \u00a0: 10,<\/span><br \/>\n<span style=\"color: #339966;\"> marginLeft\u00a0\u00a0 \u00a0: 10<\/span><br \/>\n<span style=\"color: #339966;\"> },&#8217;fast&#8217;);<\/span><br \/>\n<span style=\"color: #339966;\"> });<\/span><br \/>\n<span style=\"color: #339966;\"> });<\/span><\/p>\n<p><span style=\"color: #339966;\">\/\/ By triggering the custom events below, we can<\/span><br \/>\n<span style=\"color: #339966;\"> \/\/ show the previous \/ next images in the slideshow.<\/span><\/p>\n<p><span style=\"color: #339966;\">slideShow.bind(&#8216;showNext&#8217;,function(){<\/span><br \/>\n<span style=\"color: #339966;\"> slideShow.trigger(&#8216;rotateContainer&#8217;,[&#8216;next&#8217;,90]);<\/span><br \/>\n<span style=\"color: #339966;\"> });<\/span><\/p>\n<p><span style=\"color: #339966;\">slideShow.bind(&#8216;showPrevious&#8217;,function(){<\/span><br \/>\n<span style=\"color: #339966;\"> slideShow.trigger(&#8216;rotateContainer&#8217;,[&#8216;previous&#8217;,-90]);<\/span><br \/>\n<span style=\"color: #339966;\"> });<\/span><br \/>\n<span style=\"color: #339966;\"> }<\/span><\/p>\n<p><!--more--><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Step:1 First we are going to lay down the Html markup of the slideshow. #slideShowContainer div is the main container element which holds the #slideShow div. &nbsp; &lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;meta http-equiv=&#8221;Content-Type&#8221; content=&#8221;text\/html; charset=utf-8\u2033 \/&gt; &lt;title&gt;Rotating Slideshow With jQuery and CSS3 | Tutorialzine Demo&lt;\/title&gt; &lt;link rel=&#8221;stylesheet&#8221; type=&#8221;text\/css&#8221; href=&#8221;css\/styles.css&#8221; \/&gt; &lt;\/head&gt; &lt;body&gt; &lt;div id=&#8221;slideShowContainer&#8221;&gt; &lt;div [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3431","post","type-post","status-publish","format-standard","hentry","category-whats-trending-web-design"],"_links":{"self":[{"href":"https:\/\/www.searchenginegenie.com\/web-design-blog\/wp-json\/wp\/v2\/posts\/3431","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.searchenginegenie.com\/web-design-blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.searchenginegenie.com\/web-design-blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.searchenginegenie.com\/web-design-blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.searchenginegenie.com\/web-design-blog\/wp-json\/wp\/v2\/comments?post=3431"}],"version-history":[{"count":74,"href":"https:\/\/www.searchenginegenie.com\/web-design-blog\/wp-json\/wp\/v2\/posts\/3431\/revisions"}],"predecessor-version":[{"id":3506,"href":"https:\/\/www.searchenginegenie.com\/web-design-blog\/wp-json\/wp\/v2\/posts\/3431\/revisions\/3506"}],"wp:attachment":[{"href":"https:\/\/www.searchenginegenie.com\/web-design-blog\/wp-json\/wp\/v2\/media?parent=3431"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.searchenginegenie.com\/web-design-blog\/wp-json\/wp\/v2\/categories?post=3431"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.searchenginegenie.com\/web-design-blog\/wp-json\/wp\/v2\/tags?post=3431"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}