The new design on Themes by bavotasan.com required a content slider so I built a simple jQuery plugin that would work the way I needed it to. There isn’t much to it but you can set the speed, slide timer, easing and if you want it to work solely as a content slider or as a slideshow. It even loops so you don’t have any of that ugly backwards sliding when it hits the end.
Here is the basic CSS you need:
#sliderota { width: 900px; /* change to the width you want */ height: 380px; /* change to the height you want */ overflow: hidden; position: relative; background: url(../images/bigad_bg.png) no-repeat; } #sliderota .slides { position: absolute; top: 0; left: 0; } #sliderota img { float: left; } #sliderota ul { position: absolute; bottom: 10px; left: 10px; z-index: 100; list-style: none; padding: 0; margin: 0; } #sliderota ul li { float: left; } #sliderota ul li a { background: url(../images/controls.png) no-repeat 0 0; width: 16px; height: 16px; display: block; } #sliderota ul li.selected a { background-position: -18px 0; } #sliderota .controls a { z-index: 100; position: absolute; right: 10px; bottom: 10px; background: url(../images/controls.png) no-repeat -54px 0; width: 16px; height: 16px; } #sliderota .controls a.play { display: none; background-position: -36px 0; }
Here is the basic HTML:
Of course, you need to call jQuery and the plugin function:
If you are only using jQuery 1.3.2, then you will also have to include the Easing plugin to use the advanced easing options that are included in the Core UI v1.8.0.
And now for the plugin:
/** * jQuery.sliderota * Version 1.0 * Copyright (c) 2010 c.bavota - http://bavotasan.com * Dual licensed under MIT and GPL. * Date: 04/22/2010 **/ (function($) { $.fn.sliderota = function(options) { // setting the defaults // $("#sliderota").sliderota({speed: 3000, timer: 6000, slideshow: true, easing: "easeInOutQuint"}); var defaults = { speed: 3000, timer: 6000, slideshow: true, easing: 'easeInOutQuint' }; var options = $.extend(defaults, options); // and the plugin begins return this.each(function() { // initializing the variables var loop, counter, obj, totalWidth, itemWidth, curLeft, itemNum, limit; // creating the object variable obj = $(this); counter = 0; itemWidth = obj.find(".slides").width(); itemNum = obj.find(".slides a").length; totalWidth = (itemNum + 1) * itemWidth; limit = -(itemNum * itemWidth); obj .find(".slides").css({ width: totalWidth+"px" }) .end() .append("
The options are pretty simple:
$("#sliderota").sliderota({ speed: 3000, timer: 6000, slideshow: true, easing: "easeInOutQuint" });