{"id":17,"date":"2011-02-01T19:16:21","date_gmt":"2011-02-01T19:16:21","guid":{"rendered":"http:\/\/sitekicker.uwsweb.com\/blog\/?p=17"},"modified":"2011-02-01T19:17:10","modified_gmt":"2011-02-01T19:17:10","slug":"basic-jquery-rotator","status":"publish","type":"post","link":"https:\/\/www.sitekickr.com\/blog\/basic-jquery-rotator\/","title":{"rendered":"Basic jQuery Rotator"},"content":{"rendered":"<p>There are hundreds of jQuery rotator \/ slideshow plugins out there, but at some point, you may decide that your needs to very specific. The code below should provide a basis for creating your own jQuery rotator. This code will also degrade gracefully if JavaScript is not enabled on a given browser.<\/p>\n<h3>The HTML<\/h3>\n<p><code>&lt;div id=&quot;slide-wrapper&quot;&gt;<br \/>\n\t&nbsp;&nbsp;&nbsp; &lt;div class=&quot;slide&quot;&gt;<br \/>\n\t<\/code><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;!-- rotating content goes here --&gt;<br \/>\n\t<\/code><code>&nbsp;&nbsp;&nbsp; &lt;\/div&gt;<br \/>\n\t&nbsp;&nbsp;&nbsp; &lt;div class=&quot;slide initial-hide&quot;&gt;<br \/>\n\t<\/code><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;!-- rotating content goes here --&gt;<br \/>\n\t<\/code><code>&nbsp;&nbsp;&nbsp; &lt;\/div&gt;<br \/>\n\t&nbsp;&nbsp;&nbsp; &lt;div class=&quot;slide initial-hide&quot;&gt;<br \/>\n\t<\/code><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;!-- rotating content goes here --&gt;<br \/>\n\t<\/code><code>&nbsp;&nbsp;&nbsp; &lt;\/div&gt;<br \/>\n\t&lt;\/div&gt;<br \/>\n\t<\/code><\/p>\n<h3>The CSS<\/h3>\n<p><code>#<\/code><code>slide-wrapper<\/code><code> { position: relative; height: 400px; }<br \/>\n\t#<\/code><code>slide-wrapper<\/code><code> div.slide { position: absolute; }<br \/>\n\t#<\/code><code>slide-wrapper<\/code><code> .initial-hide { display: none; }<br \/>\n\t<\/code><\/p>\n<h3>The jQuery<\/h3>\n<p><code>var currentPosition = 0;<br \/>\n\tvar totalSlides = 0;<\/p>\n<p>\t$(document).ready(function() {<br \/>\n\t&nbsp;&nbsp;&nbsp; <br \/>\n\t&nbsp;&nbsp;&nbsp; \/\/ slides<br \/>\n\t&nbsp;&nbsp;&nbsp; totalSlides = $(&#39;#slide-wrapper .slide&#39;).length;<br \/>\n\t&nbsp;&nbsp;&nbsp; setTimeout(&#39;transition()&#39;, 3000);<br \/>\n\t&nbsp;&nbsp;&nbsp; <br \/>\n\t});<\/p>\n<p>\ttransition = function() {<br \/>\n\t&nbsp;&nbsp;&nbsp; currentPosition++;<br \/>\n\t&nbsp;&nbsp;&nbsp; lastPosition = currentPosition - 1;<br \/>\n\t&nbsp;&nbsp;&nbsp; if (currentPosition == totalSlides)<br \/>\n\t&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; currentPosition = 0;<br \/>\n\t&nbsp;&nbsp;&nbsp; <br \/>\n\t&nbsp;&nbsp;&nbsp; if (lastPosition &lt; 0)<br \/>\n\t&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; lastPosition = totalSlides - 1;<br \/>\n\t&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br \/>\n\t&nbsp;&nbsp;&nbsp; $(&#39;#<\/code><code>slide-wrapper<\/code><code> .slide:eq(&#39; + lastPosition + &#39;)&#39;).fadeOut(&#39;slow&#39;);<br \/>\n\t&nbsp;&nbsp;&nbsp; $(&#39;#<\/code><code>slide-wrapper<\/code><code> .slide:eq(&#39; + currentPosition + &#39;)&#39;).fadeIn(&#39;slow&#39;);<br \/>\n\t&nbsp;&nbsp;&nbsp; <br \/>\n\t&nbsp;&nbsp;&nbsp; setTimeout(&#39;transition()&#39;, 3000);<br \/>\n\t}<br \/>\n\t<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>There are hundreds of jQuery rotator \/ slideshow plugins out there, but at some point, you may decide that your needs to very specific. The&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"amp_status":""},"categories":[5],"tags":[11,10],"_links":{"self":[{"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/posts\/17"}],"collection":[{"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/comments?post=17"}],"version-history":[{"count":3,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/posts\/17\/revisions"}],"predecessor-version":[{"id":20,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/posts\/17\/revisions\/20"}],"wp:attachment":[{"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/media?parent=17"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/categories?post=17"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/tags?post=17"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}