posted on:January 6, 2009
jQuery plugin Easy Image or Content Slider
Click here for the new version of this plugin
This is my first jQuery plugin. I wrote several jQuery scripts but never made a real plugin just because I was I afraid of it’s complexity. It turned out to be a lot easier than I thought so I went ahead and created this one.
Easy Slider (as I call this plugin) enables images or any content to slide horizontally or vertically on click. It is configurable with css alone. So, basically you link to plugin file, set the content up and style it with css.
Getting Started
First you’ll need content and it should be wrapped inside a div containing an ordered list where each list item represents one slide. Here’s a markup example:
<div id="slider"> <ul>
<li>content here...</li> <li>content here...</li> <li>content here...</li> ... </ul> </div>
You can basically put whatever you want inside list items as long as you keep the same dimensions. My initial idea was to use this slider for image gallery as on Templatica’s homepage but I’ve used it for other stuff too.
To activate the script you will need to download the files, place jQuery file and easySlider.js somewhere on your site and link to them:
<script type="text/javascript" src="/js/jquery.js"></script> <script type="text/javascript" src="/js/easySlider.js"></script>
The action starts when you add this lines of code to your JavaScript:
$(document).ready(function(){
$("#slider").easySlider();
});
This basically initiates the script on page load where "#slider" is css selector of the element(s) that you wish to apply script to. You can also use multiple elements using their class names i.e. $(".list").easySlider();
Next is up to your preferences – styling. This is how default styling looks like:
#slider ul, #slider li{
margin:0;
padding:0;
list-style:none;
}
#slider, #slider li{
width:500px;
height:200px;
overflow:hidden;
}
span#prevBtn{}
span#nextBtn{}
Not much there, is it? The most important thing here is to keep the same dimensions for the content area and each list item (slide). Also, overflow:hidden is obligatory. Other than that, you have free hands in adding your own style to the Easy Slider! To get an idea how it can be spiced up, you may take a look at Templatica’s homepage.
How does it all work
Script automatically adds "previous" and "next" buttons in form of span elements with nested anchors just after the content element. Spans have assigned IDs that you can use for css selecting:
<span id="prevId"><a href="javascript:void(0);">Previous</a></span> <span id="nextBtn"><a href="javascript:void(0);">Next</a></span>
On each click (previous or next button) script calculates the current "position" and makes a one step in requested direction. So, the slider jumps from one slide to another. Once it reaches the end (last slide), the "next" button fades away and re-appears only if "previous" button is clicked again. Same goes for sliding towards the beginning.
Options
The following options are configurable:
- prevId – id for "previous" button
- prevText – text for "previous" button
- nextId – id for "previous" button
- nextText – text for "next" button
- orientation – horizontal or vertical, horizontal is default and if you want vertical set this to ‘vertical’
- speed – animation speed in milliseconds, default value is 800
Yes, you saw it correctly, vertical sliding is also possible!
Options are added when calling the script:
$(document).ready(function(){
$("#slider").easySlider({
prevText: 'Previous Slide',
nextText: 'Next Slide',
orientation: 'vertical'
});
});
Make sure that you don’t put the comma after last option.
Demos
Here are some blank, non styled demos. Check out the script in action:
To check out styled demo, please visit Templatica.
What makes this slider script different
Because of it’s simplicity and light-weightness (is that a word ?! ) I believe that is is much easier to deal with this plug in and configure it. The appearance is totally editable with css so all of you afraid of getting their hands dirty with JS code can easily use this.
Enjoy!
Enjoyed the article?
Then don't miss our next one! Subscribe to our RSS feed or share it with your friends.
Share on FacebookTweet thisDeliciousStumbleUpon RedditSubscribe
Comments (169 Comments)
Sorry, the comment form is closed at this time.
Martin Muehl
January 6, 2009
cssglobe
January 6, 2009
V1
January 6, 2009
Chris Barnett
January 6, 2009
cssglobe
January 6, 2009
crs
January 6, 2009
andreas
January 6, 2009
Pieter B.
January 6, 2009
cssglobe
January 6, 2009
Brenelz
January 6, 2009
Brandon Cox
January 6, 2009
Al
January 6, 2009
mbh
January 6, 2009
cssglobe
January 6, 2009
cssglobe
January 6, 2009
Ozh
January 6, 2009
Graeme Mac
January 7, 2009
Fabryz
January 7, 2009
Matt Williamson
January 7, 2009
Raymond Selda
January 7, 2009
Gerd
January 7, 2009
cssglobe
January 7, 2009
Janko
January 7, 2009
Elena
January 7, 2009
Richard Standbrook
January 7, 2009
Jason Judge
January 7, 2009
renjunlong
January 7, 2009
Designer
January 7, 2009
komax
January 7, 2009
Fouad Masoud
January 7, 2009
Mayco
January 7, 2009
ignari
January 7, 2009
ignari
January 8, 2009
Elvis
January 8, 2009
genia
January 8, 2009
David Toms
January 8, 2009
Abhisek
January 9, 2009
stalkerX
January 9, 2009
germo
January 9, 2009
Workingman
January 9, 2009
komax
January 9, 2009
Joseph Pecoraro
January 9, 2009
mohammed tantsh
January 9, 2009
Joseph Pecoraro
January 10, 2009
Joseph Pecoraro
January 10, 2009
cssglobe
January 10, 2009
Nitin Parmar
January 10, 2009
Joshua (Bada Bing!)
January 10, 2009
Necro
January 10, 2009
cssglobe
January 10, 2009
Davor Peic
January 11, 2009
Brian
January 11, 2009
Phil
January 12, 2009
Merewald Valletta
January 13, 2009
Kadir GUNAY
January 13, 2009
5antom
January 13, 2009
ne2d
January 13, 2009
Joe Weber
January 13, 2009
Suzy
January 15, 2009
Syl
January 15, 2009
Tim
January 16, 2009
Frederic
January 16, 2009
Max
January 17, 2009
Max
January 17, 2009
Max
January 18, 2009
Khaled
January 19, 2009
dende
January 20, 2009
Fredrik
January 20, 2009
Gaspard
January 20, 2009
Yman
January 21, 2009
Yman
January 21, 2009
cssglobe
January 21, 2009
East
January 21, 2009
Nandx
January 21, 2009
cssglobe
January 21, 2009
East
January 21, 2009
Images use instead of text
January 22, 2009
Joe
January 22, 2009
jeroen
January 23, 2009
Adeline
January 24, 2009
Dee
January 25, 2009
Nandx
January 25, 2009
cssglobe
January 25, 2009
Jose Castillo Areiza
January 26, 2009
cam filmi
January 26, 2009
sergey
January 26, 2009
zarouk
January 26, 2009
Geoff
January 27, 2009
Nicolas Borda
January 27, 2009
Nicolas Borda
January 27, 2009
Andre
January 28, 2009
Jason
January 29, 2009
cssglobe
January 29, 2009
cssglobe
January 29, 2009
Sinister Edd
February 10, 2009
Dan
February 11, 2009
danreb
February 14, 2009
Jennae Petersen
February 19, 2009
Miles Tinsley
February 22, 2009
nobull
February 22, 2009
kapil jagtap
February 25, 2009
Val
February 25, 2009
Val
February 25, 2009
jBay
February 26, 2009
Zend
February 26, 2009
josh
March 3, 2009
Peter
March 4, 2009
Roki
March 4, 2009
Mike H
March 10, 2009
Peter
March 10, 2009
Ant
March 11, 2009
Peter
March 11, 2009
netmastan
March 12, 2009
Joachm
March 12, 2009
SK
March 15, 2009
Allan Fonseca
March 15, 2009
ortak miras
March 18, 2009
Noski
March 18, 2009
Noski
March 19, 2009
Tiago Celestino
March 20, 2009
Jason Geyer
March 22, 2009
Nate
March 23, 2009
Andrei
March 23, 2009
Tim
March 26, 2009
Enrique
March 26, 2009
Drew
March 27, 2009
Charlie Rogers
March 31, 2009
Daniel Craig Jallits
April 3, 2009
José Airosa
April 15, 2009
Jean Marie
April 16, 2009
Zdeněk Doležal
April 17, 2009
Amit Dixit
April 20, 2009
Logan
April 25, 2009
Mike Lewek
April 27, 2009
Mike Lewek
April 27, 2009
peter
April 28, 2009
Mike Lewek
April 29, 2009
Bakadesu
May 1, 2009
mike
May 4, 2009
Ankit Sabharwal
May 5, 2009
Dimitris
May 10, 2009
cmd
May 15, 2009
Sjoerrigter
May 16, 2009
Hussain
May 17, 2009
ayoub
May 19, 2009
Jonathan
May 19, 2009
Mike
May 20, 2009
Sven
May 20, 2009
Sunil Rawat
May 22, 2009
sjoerrigter
May 23, 2009
wirpo032
May 23, 2009
Robert
May 25, 2009
Lorenzo
May 26, 2009
_Undefined
June 5, 2009
Mike Lewe
June 9, 2009
Umar Zaman
June 11, 2009
Jonathan
June 15, 2009
Daveed Flexer
June 15, 2009
Guillermo horno
June 15, 2009
nico4peace
June 16, 2009
Lincoln
June 17, 2009
Paul
June 17, 2009
Vishal
June 18, 2009
Adrian G
June 19, 2009
Empee
June 26, 2009
james
June 27, 2009
Vernon
June 29, 2009
dynagirl
June 29, 2009
adibu
June 30, 2009