Automatic Image Slider w/ CSS & jQuery
Tags: Intermediate, Widgets
With the release of the iPad and its lack of support for flash, it has stirred up a lot of debates regarding the future of flash. With this in mind, I believe it is wise to build simple widgets like the image slider using HTML/CSS/Javascript, and leave more interactive applications for flash if needed. The html based image slider will have its benefits with SEO and will also degrade gracefully for those w/out js.

The Wireframe – HTML
Start with having a wrapping container div called main_view, and two sections nested inside called image_reel and paging. The image_reel will contain the sliding images, and paging contains the paging controls. Take a look at the image below for a visual.

<div class="main_view">
<div class="window">
<div class="image_reel">
<a href="#"><img src="reel_1.jpg" alt="" /></a>
<a href="#"><img src="reel_2.jpg" alt="" /></a>
<a href="#"><img src="reel_3.jpg" alt="" /></a>
<a href="#"><img src="reel_4.jpg" alt="" /></a>
</div>
</div>
<div class="paging">
<a href="#" rel="1">1</a>
<a href="#" rel="2">2</a>
<a href="#" rel="3">3</a>
<a href="#" rel="4">4</a>
</div>
</div>
Styling – CSS
Take a look at the comments below for an explanation of the styles.
/*--Main Container--*/ .main_view { float: left; position: relative; } /*--Window/Masking Styles--*/ .window { height:286px; width: 790px; overflow: hidden; /*--Hides anything outside of the set width/height--*/ position: relative; } .image_reel { position: absolute; top: 0; left: 0; } .image_reel img {float: left;} /*--Paging Styles--*/ .paging { position: absolute; bottom: 40px; right: -7px; width: 178px; height:47px; z-index: 100; /*--Assures the paging stays on the top layer--*/ text-align: center; line-height: 40px; background: url(paging_bg2.png) no-repeat; display: none; /*--Hidden by default, will be later shown with jQuery--*/ } .paging a { padding: 5px; text-decoration: none; color: #fff; } .paging a.active { font-weight: bold; background: #920000; border: 1px solid #610000; -moz-border-radius: 3px; -khtml-border-radius: 3px; -webkit-border-radius: 3px; } .paging a:hover {font-weight: bold;}
Step 3. Setting up jQuery
For those who are not familiar with jQuery, do check out their site first and get an overview of how it works. I’ve shared a few tricks that I have picked up along the way, you can check those out as well.
Initial Step – Call the jQuery file
You can choose to download the file from the jQuery site, or you can use this one hosted on Google.
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script>
Directly after the line where you called your jQuery, start a new <script> tag and start your code by using the $(document).ready event. This allows your jQuery code to run the instant the DOM is ready to be manipulated. The code you will be writing in the next few steps will all take place within.
$(document).ready(function() {
//Code goes here
});
Step 4. Bringing it to Life – jQuery
The following script contains comments explaining which jQuery actions are being performed.
Setting up the Image Slider
Start by showing the paging and activating the first link. Then we will calculate and adjust the width of the image_reel according to how many slides there are.
//Show the paging and activate its first link $(".paging").show(); $(".paging a:first").addClass("active"); //Get size of the image, how many images there are, then determin the size of the image reel. var imageWidth = $(".window").width(); var imageSum = $(".image_reel img").size(); var imageReelWidth = imageWidth * imageSum; //Adjust the image reel to its new size $(".image_reel").css({'width' : imageReelWidth});
Setting up the Slider Function and Timer
We first create the function for the slide event by itself (rotate). Then create another function (rotateSwitch) that will rotate and repeat that slide event (rotate).
//Paging and Slider Function rotate = function(){ var triggerID = $active.attr("rel") - 1; //Get number of times to slide var image_reelPosition = triggerID * imageWidth; //Determines the distance the image reel needs to slide $(".paging a").removeClass('active'); //Remove all active class $active.addClass('active'); //Add active class (the $active is declared in the rotateSwitch function) //Slider Animation $(".image_reel").animate({ left: -image_reelPosition }, 500 ); }; //Rotation and Timing Event rotateSwitch = function(){ play = setInterval(function(){ //Set timer - this will repeat itself every 7 seconds $active = $('.paging a.active').next(); //Move to the next paging if ( $active.length === 0) { //If paging reaches the end... $active = $('.paging a:first'); //go back to first } rotate(); //Trigger the paging and slider function }, 7000); //Timer speed in milliseconds (7 seconds) }; rotateSwitch(); //Run function on launch
Take a look at this tutorial for an explanation of how the timer (setInterval) works.
Hover and Click Events
In case the user wants to view the slide for a longer period of time, we will allow the slider to stop when it is hovered. Another thing to consider is we should reset the timer each time the paging is clicked. This will prevent unexpected slide switches and allow for a smoother experience.
//On Hover $(".image_reel a").hover(function() { clearInterval(play); //Stop the rotation }, function() { rotateSwitch(); //Resume rotation timer }); //On Click $(".paging a").click(function() { $active = $(this); //Activate the clicked paging //Reset Timer clearInterval(play); //Stop the rotation rotate(); //Trigger rotation immediately rotateSwitch(); // Resume rotation timer return false; //Prevent browser jump to link anchor });
Inspiration
Below are some sites that use similar techniques, check them out for inspiration!
Related Articles
Related Posts
Author Bio
My name is Soh Tanaka and I am a Los Angeles based designer/front-end developer specializing in CSS driven web design with an emphasis on usability and search engine optimization. I also run a CSS Gallery which is updated daily with the best CSS websites from around the world. Come check it out!
You can learn more about me or
Follow me on twitter for more updates and resources!
Did You Enjoy This Post?
Subscribe via RSS or by email to get all upcoming tutorials and articles delivered straight to you.









+ Add Comment205 Peeps Have Spoken Their Minds...
Excellent, as usual.
Thanks.
Great tutorial thanks.
Awesome tutorial, Soh! I love the illustrations on the slides.
Glad you are finally back to posting tutorials Soh.
This looks excellent. Very nice effect and very useful. I’m a huge fan of your tutorials. They are always very detailed. See you tomorrow.
Nice to see you’re back with new tuts. Thanks.
Excellent! I liked how you kept it clean and simple! Keep up the good work!
Great stuff, even I understand how it works. :) I’ll use that on my new website. Thanks a lot!
This is definitely something I have seen on a fair few websites.
Ill be keeping this in mind for the next project!
Thanks
:)
fantastic one as usual. thanks dear
Ahmed
really a gr8 simple n understandable script.
thankx for sharing it.
lol i was just about to add one of these to a front page for a client when you came along with your solution.
the clients old website had flash on the frontpage for things like this and so i advised them to use alternatives.
great work as always
Very nice! Thank you.
Great Tutorial / Slider :)
Nice smooth automated effect
Great to see you back in action :)
Thank you for the tutorial :)
Building one of these is on my agenda for later in the week. Perfect timing. Thank you!
Finally :) Great tut to start new season!
was looking for a simple way to do this…
i wanted an easy way to build a slider plugin for wp, and this worked perfectly…
thanks…
Thanks soh,
can you tell me, how i can put there a next and preview?
i look your code, and i dont know how you go that way..
i am a new in javascript, do you know where i can study that?
thx soh,
cya
Brilliant, is it possible to replace the images with div tags so that the jquery uses the div’s to swipe swipe rather than images?
Great tutorial thanks.
What will happen if the images are not of the same size?
Dope slide show – time to update the one on my site. Thanks for the tut!
Great tut, thanks!
Amazing as usual Soh! Thanks :)
awesome slider thanks
Gorgeous. Though, I’d suggest resetting the timer every time a user manually switches slides.
I’ve been looking for something like this for ages !
Thank You So Much !
Great tutorial Soh. This jQuery slider is awesome!
I’ve been searching everywhere for this jquery slider code! I even bought a month subscription on lynda.com for help. Couldn’t find it there either. Until now….THANKS TO YOU! THANK YOU. THANK YOU.
Fantastic as always, I love these things as they let users know how many images/banners are available to view and they are so easy to use.
Thanks again.
Amazing…
Superb this would be great to implement in a portfolio, Thanks.
There is a typo I think for tutorial9 link. The correct link is tutorial9.net, not .com
Soh thats a neat tutorial! Will use it in some of my projects.
Looking forward for next tutorial ;)
excellent … very helpful as usual
Nice custom image slider with just few lines of code.
Intresting solution. Thanks
Amazing tut !
Hi Soh,
really intersting stuff, i was searching for a flash alternative for this…
I made a quick test here: http://www.jangeloen.be/new/test1.html to see what i could do with your idea. My question is now, is it in any way possible to have more than one of these running on one page? (is the only way by giving each instance its own piece of j code?)
What’s happening with the timer? It works fine for you on FF and IE?
Nice slider Soh
I disabled the timer (I just removed the “rotate” command in the timer section)
@Matias I will probably have to write an addon tutorial to this to show you~
@Duncan Turner yes, you can replace it with a div if you would like.
@John Johnson you should have them consistent in size since they are moving through the masked window which is a fixed size.
@Alique Azmi thanks for catching that! I fixed it to .net :-)
@Jan Geloen I would advise not to have multiple automatic rotations running on the same page at once. But if you would like to use multiple image slider w/out auto rotations, I have another tutorial I will post later :-)
Can somebody advice how to made fade effect when image is changes?
Thx Soh!
very useful :)
Awesome slider. So simple and easy to integrate, but still looks great.
Thanks for sharing.
Kevin
I’m looking forward to that tutorial ! thx a lot :)
Great tutorial! I love the outcome :)
Firstly, Soh, fantastic work with all your tutorials, I’ve found them to be invaluable. I was wondering what the best way to go combining this with a previous tutorial of yours would be (http://www.sohtanaka.com/web-design/css-on-hover-image-captions/)? Is their a simpler way than changing the class call to seperate ids (each with their own positioning)?
Thanks again for all your tutorials!
thats great stuff. thx a lot for this tutorial
This is great. Your jQuery tutorials are second to none. I love the design of your examples and I love how your code is clean and efficient.
I want to take this example and add a panning effect to the images. :-)
Looks great thanks for making this.
One thing I’d like to point out however, it pauses when you hover over the image but not when you hover over the controls. This can be a little confusing until you realise what’s happening.
Should be easy to sort but I thought I’d mention it here.
This is a great find, thanks for posting it.
I am really new new to jquery and this to me quite a while to get working but finally did.
I have been trying to tweak it a bit more. I’d like to add a transparent bar and add a message scroller to it like they did on the site shown under inspiration ( http://www.netdreams.co.uk/
I tried all day trying to figure it out with no luck. I though the transparent image would be added like this but couldn’t get it.
.paging {
position: absolute;
bottom: 10px; right:;
width: 790px; height:37px;
z-index: 100;
/*–Assures the paging stays on the top layer–*/
text-align: right;
line-height: 40px;
background: url(image-files/transparent.png) no-repeat;
display: none; /*–Hidden by default, will be later shown with jQuery–*/
}
Sure there are a ton of people here that are smarter then me, would really appreciate any help and try to play it forward
thanks
Scott V aka fotodog13
muchas gracias, es fantastico, me será de gran utilidad…
saludos,
Felipe Saavedra E.
Nice tutorial.
Is there a way to enable the slidings only after all the images have fully loaded?
Great plugin, although I would suggest not changing the font-weight on hover. Changing the dimensions of any inline element on hover jerks the rest of the content around.
Nice work!
Nice! I use a similar jQuery solution for my webpage as well. But I like that this one pauses on mouse-over.
This is really nice the images are equally cute :) just one thing though can the animation style be changed easily? I am pretty sure if I have this on my site I’ll get sued for causing epilepsy fits :P
Thanks for the excellent plugin. Perfect for a car website im working on right now! been after something like this for the past 30 minutes. Brilliant!
Hi, This is really nice slideshow, especially the pause on hover..
Just wondering, is there a way to put next and previous button on that slideshow.
Thanks.
Really simplistic and super cool too. I like it.
Perfect! This is exactly what I was looking for and the inspiration is great!
hi ……. how about using text over slideshow too…that will be great!
Hey, thanks for sharing this. I have been searching high and low for a slider that is easily customizable, and easy to understand and implement. Finally I can look no further. Waqas above has a great idea, any way to implement text padded to the left or right or top or bottom of the image as well? That would be even better .. not that I'm complaining mind you. I gave you a shout out on Twitter for this post ( http://clicky.me/GVB )… thanks again .
Nice tutorial! I’ve set an id to my different slides, and by adding #example
to the url it would go to that particular slide. However if I do this the menu will set the first tab to active in the navigation ofcourse and #example could be tab 3. Any Ideas on how to get around this ?
Thanks for sharing Soh!
It is very useful and it was easy enough to understand too. I’ll be looking for more of your posts! Thanks again!
Dude – awesome tutorial. I’ll let you know when my version is live on my website. We’re rolling out a new site design on Friday and we’ve been looking for an option of this sort. Yours seems to the easiest solution we’ve found.
Cheers,
JB
Fantastic Soh!
Your SEO is just pure awesome… I typed in “html, css, content slider” and your tutorial was in the top 5 results! Looks like you’ve come a long way with understanding JavaScript/jQuery. I’ve yet to really dig into it but maybe you could help me start that journey.
I was wondering if there is a way to repurpose this content slider to rely on a “Prev” and “Next” button. Basically, I already have a layout with the aforementioned type of pagination. How would I go about hooking this up with my pagination?
Thanks and nice work as always. Repping’ the South Bay! ;)
useful tutorial :)
I like Dey’s idea of Next and Previous buttons.
I am also wondering why you didn’t us an ordered list for the paging? Are you able to?
The degradation when there’s no javascript is also very well done.
@Ben
It’s not much work to use an ordered list with this slider. As long as the tags have the rel attributes, you can wrap them in s and s.
I’m still trying to figure out how to implement a Prev-Next pagination. My JavaScript isn’t very strong as I’ve spent most of my resources learning PHP and MySQL. I do have a little bit of AS3 knowledge and so I can sort of understand JavaScript (both ECMA based languages) like the code that is already written, but to repurpose, that takes a bit of knowledge of syntax and I’m assuming DOM to target elements.
Soh what’s up Soh? :P
oops, my tags got stripped. The sentence should read, “you can wrap them in lis and uls.”
Really nice tutorial as usual!
I’m surfing your blog daily and things here keep amaze me :)
I read somewhere that you “love” wordpress, how would you go if you wanted to impement this slider on a wordpress site, and instead of showing images, it shows posts with a certain category? ie. “Featured posts”.
Regards
To2
one of the most elegant jquery carousels I’ve seen, and you also make it look so easy to implement, thank you for the great resource!
Great tutorial as always Soh!!! thanks a lot, just keep the great stuff coming :P
Hey! what do you know!
I got it working after a long night by adding “new WP_query” to generate a second (separate) loop :)
But I wouldn’t mind reading a tutorial here on your blog though! :)
-To2
What if we keep paging div empty and add this on top..
//get total items
var i = 1;
$(“.image_reel li”).each(function(){
$(“.paging”).append(‘‘ + i++ +’‘);
});
P.S – I used instead of images in my reel
thanks, great tutorial…
@fotodog13 – Look at http://24ways.org/2009/working-with-rgba-colour for inspiration :-)
Now can anybody tell me how to insert a loading animation whilst the first image is loading? Any tips would be useful thanks…
Rob.
Awesome Tutorial Soh!
Had a play around with the code last night and it worked really well.
Many thanks
Rob
@Rob_Jones
How about putting a lightweight ‘loading’ or ‘please wait’ background image into .main_view ?
A bit of a cheat but should do the trick. :)
Rob
Question: Is it possible to use an image map with this slider? My last slide (out of 18) has a link URL in the image.. my client would love to have that link active. I’m not sure if setting up an image map would make that area active on every slide, or just that last one.. Any insight is greatly appreciated!
I am not too good with JQuery…but I need something similar.
The images are loading on siteload..or are loading when the button is pressed?
simple but very nice and useful!
Thanks!
How to do fadeIn/fadeOut insted of slideing?
dood you are an absolute legend!!! another great tutorial, thanks!
This was a great tutorial, easy to follow and worked great. However I am interested in figuring out how to apply thumbnail images rather than numbers like the “Tutorial9″ homepage slider.
Any chance you could make an addition to this tutorial using thumbnail images that match the large image instead?
Very nice!!! It help me a lot. Thank you!
Excellent tutorial! thanks a lot, im gonna use it in a project i have and send you the link later :D
Excellent tutorial..! Thanks for sharing..!!
what about go to another page insteas of restart slideshow when paging finishes? is that possible?
Beautiful tutorial, very great!
Excellent script once again!
I tried to modify a few things so that I could rotate DIVs instead of images. Everything seems to work great – BUT – if you happen to click on a few tabs on rapid succession, somehow when the automatic rotation resumes, the Interval gets all messed up. You end up having some DIVs showing for 1-2 seconds each, then jumping 3-4 DIVs without any pause on each, and then pausing again for the set 10 seconds (which was my original interval setting).
Does anyone know what might cause this issue? I thought the “on click” function reset all timers but somehow this is not working and is causing random intervals.
Any help/suggestions would be much appreciated!
As usual, excellent tutorial! It’s your eye for design paired with solid programming that really make your tutorials stand out.
Slightly embarrassing but important question, but are your Blog coding samples open-source (MIT license)? I would love to use some of these coding snippets in my own projects, but don’t want my freelance clients to get a cease-and-desist email or worse…! :)
You can use the code as you wish :-) My goal is for you to learn these techniques and build something great out of them~ Good luck!
Very nice tutorial, however I struggled for a couple of hours until I compared the code above to the source on your demo page. Please instruct people that they must set a class or other style that makes the img borders = 0 otherwise everything breaks.
Hey bud.. another awesome tutorial.. this is one, however, I can not figure out why it doesnt want to work. Here is the link to the example page:
http://96.9.157.245/~rrochlin/
the boxer image should be sliding to four different images. I dont know if some other jquery is getting in the way? Or its not firing – i haven’t a clue.
I am pretty new with jquery and I know right now the of my page is cluttered with a few bits of javascript.. my goal was to get them all working the way they should and put them in an external file.
Any suggestions or help is greatly appreciated.
I am also wondering if anyone has an example of this slider using a fade effect instead of a linear slide.. Thanks!
That is a really nice implementation of an image slider.
this is awesome! flash is dead, long live jquery!
thanks for such a clearly explained tut…
nicely explained. cool tutorial
nice one!! what about integrating this one in to wordpress?
Cool website, love the wireframing, code examples, all looks really good. Tried to submit to digg but couldn’t get it to work :(
First: This is an awesome design and Im always looking for image sliders that work well.
Question: Is there a way to put more numbers on the navigation. Lets say you have 30-50+ images for an image viewer in a gallery how would you fit all the numbers? I was thinking putting little arrows on either end of the navigation so that you could cycle through and get to high numbers but I myself dont know how to do that. Is there a way to incorporate what im saying into this design?
Does anyone know how i can used a fade effect in the slider?
thanks, im JQuery lover. Like it
Very nice tut, thanks
Hi,
This is nice automatic slideshow. Anyway, it would be better if you have an option, like “autoplay : false;” something like that. Sometimes, people don’t want auto thing.
Thanks
Definitely your tutorial helps me out ! Thanks
Is there way to use this and have it go vertically? I really like how http://www.builtbybuffalo.com does this, but it’s mootools (which I’ve never really worked with).
Love the site, you make me look good on a daily basis (http://business.evansville.edu). Thanks!
Excellent Script!
really nice.. easy to understand.. how to use next and prev button in it….
very good
This is the coolest thing since sliced bread! Thank you so much. I’m looking to impliment this exact thing in a redesign for a client of mine. I had another client that needed me to do website updates that included adding a slide into the slider on his webpage and I was so confused. I didn’t get it. After looking through this tutorial, I feel I may be able to finally help him out…
Thanks Soh!
Hi.
Thank you so much for this tutorial… it’s just like magic.
I have one doubt, how can I change the code to make the continuos scroll? I don’t like the effect produced when you return to the first.
Thank you so much
Hell
Love your tutorial
I have added to my bookmark !
Thanks
I am using your technique with some modifications, but have run into one problem — for the design, I need to nest the .paging tags in an unordered list, which is messing up the script. Here’s a link to a detailed version of my question on stackoverflow http://stackoverflow.com/questions/2826801/jquery-slide-show-correct-trigger. Can you help a noobie?
I found an answer to the path question above. Here’s how to make it work with anchor tags nested in an unordered list:
$active = $('.paging li a.active').parent().next().find('a'); //Move to the next nav item
Great tutorial… I’m gonna use it in my next project.
HI,
I purchased this template, for my web site but I would like the slider to stop at the last photo instead of scrolling back to the beginning.
I am not a programer, and the company I bought it from says I bought what I got.
I have looked everywhere to find a way to make it stop at the last photo. Do you know how I can achieve this?
yeah, it could be nice ì f you share more
Anyone figure out how to add a prev and next…for the life of me I have not been able to there where a bunch of you trying but it seems as though no one has succeed.
I am new to jQuery, and I have one question. I am trying to incorporate this slider in a SharePoint site. It works fine in the .html file, but when I move the code to the web part on the site, there are gaps between the images. Also, the final image wraps to a second row. Am I doing something wrong? Any help would be greatly appreciated. Thanks!
pretty sweet bra,
Did something similar on my site. A friend that helped me with it linked me to this and my first thought was “dang, it would have been nice to have this a few months ago!”
Thank yoo very much! your save my day!
Hi, really good tutorial. But if I would like to show a different text for each image how can I do it?
Thank you for your help
Thanx a lot for this wonderful tut ..!! Im using it in my site right away !!
Funcionou perfeitamente!
depois de tanto tempo procurando por esse tipo de recurso para meu blogger, finalmente consegui um que funciona
thanks, this is great…
this is a grate work
thamks
This is cool. I’d like to see something like this but the different elements of the image move at different rates. The clouds, horizon, and foreground each moving at a slightly different speed could have a dramatic 3d effect.
I’m also wondering how to add a caption to each image. Even just below the paging numbers, if not a slightly opaque bar across the image.
Fantastic work, thank you so much!!
Great tutorial Soh :)
One thing though, would someone be so kind as to explain this line in excruciating detail for me? :
var triggerID = $active.attr(“rel”) – 1; //Get number of times to slide
It’s obvious what it does, but how exactly does it work?
For instance, if the slide is in position 3 and position 1 is clicked, what is the process involved with the rel attribute in correctly determining the distance it needs to slide?
@HUTCH $active.attr(“rel”) basically says, get what the rel value is in the markup. I may have complicated things by adding the – 1 in there, but that was hopefully to simply the <a href=”#” rel=”4″>4</a> so the rel and number within the a tag matches. This in the end just gets you the value of how many slides it takes to get to that slide.
Hi SOH, great rotator!
I am trying to make it rotate infinite, without going back to the first image through all the other images.
Is there a way to make it infinate? When it reacht he last frame just to continue rotating without going back?
@SOH Ah (light bulb), so it’s not so much calculating the number of times to slide, it just appears that way to the viewer, it’s really calculating the pixel coordinates where it needs to stop, which is why the – 1 is added: because the slider still needs to display the first and last frames and if it wasn’t there it would pass those frames by and display nothing.
BTW, I am working through all of your tutorials and not only are they helping me out a lot, but they are actually fun for me, and show that you’re truly passionate about your craft. From passion comes creativity, and it really shows. Great job, man, and please, keep it up.
when i am using this jquery . i am having a problem with my drop down menu. My drop down menu is goig behind the images so drop down list is not visible please anybody help its realy urgent.
is there Something like this for WordPress plugin?
I think there’s been other comments about this, but I didn’t see an answer. I want to use previous and next arrows instead of numbers, and I need to have multiple images per slide with an unlimited/uneven number of images. I figured out how to get more than one image per slide, but I’m new to jQuery so I don’t know how to make it work with an uneven number of images. Or how to use just two paging links to rotate through more than two slides. Please help meeeeee! Thank you
Nevermind… I just started from scratch and used one new snippet I learned from your code plus what I already know and made my own that works great! So thank you very much for the direction. :)
HI
This is great!
But i just implemented this and i have an issue with number of images.
i have 5 images but only 4 are being shown even if you click on the 5th link.
http://www.cyclespapillon.com
i cannot figure out why.
thanks
thx for the articles
Its gives an error if “$active not defined” please help me out i copy pasted the whole code same to same
First of all, thanks for the very nice slider. Like Jan Geloen, I tried to implement multiple sliders on one page, using different IDs. But I still couldn’t manage to have them work seperately.
Could you by chance post the tutorial about multiple sliders that you were talking about?
Thanks in advance,
–Jakob
Really beautiful tutorial.. i like your presentation style .
thanks
What about Preloading…of images ????
if you use this script on a mobil.. it´s lacks when you try to load 10 pictures
Is there any here there knows how to implemt Preloading.. ???
Very nice and clear tutorial!
I will use it on my blogs and sites.
Anyone had any luck with this working correctly in IE 8? After the first image, it starts cutting off the right side of the following images. Also, adding a fifth image doesn’t seem to work, it shows up blank. (Works fine in Firefox, Chrome). See URL:
http://georgiadogs.cstv.com/ot/stegeman-expansion/
Hi Soh,
I’m trying to get my hands dirty by writing some plugins the last few weeks, so it is very nice to have a look at how others do things.
But I have a question:
I thought that when you assign the unnamed functions to rotate and rotateSwitch, they’ll become global variables when declaring it like this.
Is this for a reason or am I mistaken?
Thanks
I am also looking for the correct method of adding a caption on top of each picture that slides in and out with it’s respective image. I have had no luck so far, they all show up on the first image.
The script is great! I know it’s possible, but can you tell me how you use Divs instead of images? I’ve tried, but can seem to target them properly.
Thank you!
@GLORIA
I second what Gloria wrote on 03/25. Everything worked wonderfully for me after I assigned an img border to 0. Firefox was displaying it wonky before I did that (Safari & Chrome worked fine… haven’t tested IE yet)
Thank you SO MUCH for the solution I’ve been searching for by posting this tutorial. Very appreciated! :)
Wow mates…. img {border: 0;} is a GIVEN. If you don’t know that and taking this tutorial, you should learn basic CSS and HTML before hand. I am shocked.
Great slider but the slider works fine but I have 4 images and it displays 3 images and on the 4th image it displays nothing.
can someone please help me with my problem.
I was helping someone add captions to this wonderful tutorial, but I thought I would share it for others. I only added a few lines to the code and HTML. Check out a demo here – http://jsfiddle.net/3TJrj/2/
Thank you so much for this outstanding tute. I’d been trying to get another slider working for 2 hours when I found this one – up and running in 25 minutes including a different pager background.
@ROB – Almost exactly perfect with those captions… can you tell me, if I want the same exact slide up and down after each image slides in. So instead of having to hover over the image to see the caption, I just want it to slide in image, then automatically slide down caption. Then slide up caption and slide out image…. then repeat for each as expected.
Thanks!
@Ryan: I’ve updated the demo (http://jsfiddle.net/3TJrj/7/) so now the comments slide in/out when an image appears. You can click on the comment to hide it. If you want to see the comment again, you’ll have to click on the paging link.
Thanks for tutorial…
http://www.raghibsuleman.com/jquery-automatic-image-slider
Thank you for the great tutorial!
The slider is working great in every browser except IE. The content to the right of the sliding content get pulled over to the left under the sliding content, and as the sliding content moves along each slide becomes smaller and the fourth slide does not show up at all. Are there any modifications I should make to resolve this?
I found a resolution to a couple of my problems. To resolve the issues with the images becoming smaller and the fourth image not showing up at all add hspace=”0″ to all of your images.
I am still having issues with it pulling the graphics, on the right, under the sliding content.
Awesome! i gonna use this!
Hi, does someone know how to link the slider images as a part of wordpress’s custom fields? There is no answer inside wordpress forum.
And this is a wonderfull piece of work, thanks!!!!!!!!!
hI GUYS!Great Tutorial but is there any chance to exchange img sliding in to img fade?
This is very nice and simple to edit. Thanks for this slider. It will come in handy in many projects!
Just exactly what I was looking for, will unashamedly copy and use on my portfolio site. Great work – cheers bud!
Vauuu this is really cool site. I was looking for a such site for a long time …. uhhh thanks to the authors.
I am trying to use this image slider along with your Horizontal Subnav with CSS.
http://www.sohtanaka.com/web-design/horizontal-sub-nav-with-css-jquery/
For some reason the submenu gets hidden behind the image slider. How can I bring the Horizontal Subnav to the front or push the Image Slider to the back?
Figured it out. I just gave the topnav a z-index: 101; which is one layer above the image slider layer of 100.
Thanks for great tutorial !
I get fade effect simply adding
$(“.image_reel”).fadeOut(600);
$(“.image_reel”).animate({ left: -image_reelPosition }, 0 );
$(“.image_reel”).fadeIn(600);
Anyone know how I can get this great slider to loop?
Thanks in advance!
MH
Quick question regarding the control button. Generally, when my page loads for the first time the control button does not appear, I hit enter again and it pops up. I think there is a default option in the js to kick the request over to the css, where the css can force the image to load. Any help would be greatly appreciated.
Yo!
Really enjoying this script, thanks big times.
Have a question though… Would it be possible to start the scrolling from another link which isn’t in the .paging class?
Cheers!
Peace from Switzerland
Great Tutorial !!!
Can I use them ? Under which license are your snippets ???
GNU GPL or what ever ??? Can i use them and is a Backlink enough ?
THX Greetz Toni
great tutorial
but, how come i can remove the “1,2,3,4″ link with just the next and prevous button
thanks
love your stuff man
hey awesome script .. how can i change the slider animation to dissolve (as opposed to horizontal sliding)? ^_^
Amazing… Thanks
Super clean script, thank you for the free-bee!
nice tutorial. :) i like the avatar who has spoon in his brain lol
Great article & also the Inspiration is very nice
fantastic really wonderful amazing and so powerful i like and also like my friend this jquery image sliding………
Great tutorial! I just have one question… How do I get rid of the space between the images? I’m using png images which have a transparent background, so in my case, this “space” is really ugly like this. I tried editing a css .image_reel but I always have this gap area between images…so where do I have to edit, css or java code?
when I implement this i must remove the absolute positioning so it fits in the target table, however in all browsers except IE8 this kills the style of whatever is directly after it, no idea why. And in IE8 the last slide is always empty
I cannot get it to pause on Hover, it simply keeps scrolling, so, it’s broken, is this due to a new version of Jquery? or what?
….okay…. i opened to the demo again and now it’s working fine and i can’t repeat what i did to break it, i have no clue why i have a tab with the demo in it and the hover pause isn’t working at all, and in another tab i have a perfect working demo, strange. chrome 5.
Great slider, is there anyway to make it start on a random slide?
I could use some help here. I’ve tried tweaking, copying, writting the code in from scratch. It works perfectly well in IE8, but in a fully updated version of Safari, it wont set active for the first image/selector, and then consequently when it reaches the end it goes past the first image to a completely empty one.
As i said, I havn’t modified a thing, but it just wont behave. Any ideas?
First of all I would like to thank you for providing such a great tutorial. It has really helped me out. I’m having a problem though. My image slider wants to skip images 2 and 4. I have a total of 4 images. Here is what happens…
1. Image #1 loads.
2. After the set time, the timer slides slides immediately past slide #2 and goes directly to #3.
3. Then it stays on slide #3 for the set time, slides past slide #4 and jumps right back to slide #1.
I can’t figure out why it is doing this. I will paste my code below. Maybe you could help me out. I followed your tutorial exactly so I’m not sure why it’s doing that.
Additionally I wanted to ask if making the images “fade” instead of “slide” would be an easy adjustment to the .js file?
Again, thank you very much for the tutorial. You really help the guys like me out (guys who aren’t that great at coding).
HTML…
1
2
3
4
CSS
/*–Main Container–*/
.main_view {
float: left;
position: relative;
}
/*–Window/Masking Styles–*/
.window {
height:377px; width: 980px;
overflow: hidden; /*–Hides anything outside of the set width/height–*/
position: relative;
}
.image_reel {
position: absolute;
top: 0; left: 0;
}
.image_reel img {float: left;}
/*–Paging Styles–*/
.paging {
position: absolute;
bottom: 10px;
right: 0px;
width: 170px;
height:45px;
z-index: 100; /*–Assures the paging stays on the top layer–*/
text-align: center;
line-height: 40px;
display: none; /*–Hidden by default, will be later shown with jQuery–*/
background-image: url(../images/image_slider_paging.png);
background-repeat: no-repeat;
}
.paging a {
padding: 5px;
text-decoration: none;
color: #fff;
}
.paging a.active {
font-weight: bold;
border: 1px solid #0000CC;
-moz-border-radius: 3px;
-khtml-border-radius: 3px;
-webkit-border-radius: 3px;
background-color: #0000FF;
}
.paging a:hover {font-weight: bold;}
JS
$(document).ready(function() {
//Set Default State of each portfolio piece
$(“.paging”).show();
$(“.paging a:first”).addClass(“active”);
//Get size of images, how many there are, then determin the size of the image reel.
var imageWidth = $(“.window”).width();
var imageSum = $(“.image_reel img”).size();
var imageReelWidth = imageWidth * imageSum;
//Adjust the image reel to its new size
$(“.image_reel”).css({‘width’ : imageReelWidth});
//Paging + Slider Function
rotate = function(){
var triggerID = $active.attr(“rel”) – 1; //Get number of times to slide
var image_reelPosition = triggerID * imageWidth; //Determines the distance the image reel needs to slide
$(“.paging a”).removeClass(‘active’); //Remove all active class
$active.addClass(‘active’); //Add active class (the $active is declared in the rotateSwitch function)
//Slider Animation
$(“.image_reel”).animate({
left: -image_reelPosition
}, 500 );
};
//Rotation + Timing Event
rotateSwitch = function(){
play = setInterval(function(){ //Set timer – this will repeat itself every 3 seconds
$active = $(‘.paging a.active’).next();
if ( $active.length === 0) { //If paging reaches the end…
$active = $(‘.paging a:first’); //go back to first
}
rotate(); //Trigger the paging and slider function
}, 5000); //Timer speed in milliseconds (3 seconds)
};
rotateSwitch(); //Run function on launch
//On Hover
$(“.image_reel a”).hover(function() {
clearInterval(play); //Stop the rotation
}, function() {
rotateSwitch(); //Resume rotation
});
//On Click
$(“.paging a”).click(function() {
$active = $(this); //Activate the clicked paging
//Reset Timer
clearInterval(play); //Stop the rotation
rotate(); //Trigger rotation immediately
rotateSwitch(); // Resume rotation
return false; //Prevent browser jump to link anchor
});
});
Thank you for your help. I fixed my problem.
Thank you sir for a great tutorial !
I have a question regarding more than one instance.
As in, if i am displaying multiple sliders on the same page. and how would one do that?
thanks in advanced and we wish you a prosperous year!
Simple and effective!Thanks a lot for sharing this tutorial.
wa….very cool!
我喜欢。。。
How I can add more than 4 images?
Hi, would I be right in thinking you can use any element instead of just an image? – I’d like to use divs with background images and links inside them.
you should really use vars for the redundant selectors to make it faster.
var paging = $(“div.paging”);
var imageReel = $(“div.image_reel”);
//Slider Animation
$(imageReel).animate({
left: -image_reelPosition
}, 500);
makes things run much faster
I really like this tutorial but I am having trouble getting the images to actually show up. The page cycler works but when i link my own images in I just get a blank screen with the page numbers cycling. My images are in the same folder as the css & html document. Any help in this matter would be greatly appreciated.
Cam
hej, im a beginner in working with java script. but im quite interessted in your work here. can you upload all files for this slider?
that would be very nice, its not easy for me to read so much on english because im no native speaker
Dear Soh,
First of all I want to thank for the wonderful resources you made available to the public. Some of them have proven indispensable for me, during my css and jquery experiments. However, I come to you now with a more than personal request.
I’ve took your Automatic Image Slider example and decided to do a bit of tinkering with it. I wanted to use Thumbnails of the images currently in the slide, instead of the boring page numbers. Also, I tried to add a neat description (with a link) for each of the images in the slide.
After I managed to do all that I got stuck at the current configuration: http://www.quicksave.ro/dev/build/slide/
As you can see, I did a pretty nifty job at achieving the desired look for the slider, but not without a few drawbacks or bugs.
First: If you click of the thumbs (paging elements) related to the slide, before the rotate() function starts to do its job, you’ll notice that the slide breaks. If you wait for it to start, and then click each thumb you’ll notice that everything works fine. Currently have no clue on how to fix it.
Second: The slide description spans only work properly if you let the slide go on by itself. No matter what slide thumb you click on after the rotate() triggers, the description span goes into a halt. I’m sure I am taking a really idiotic approach, and missing a few triggers for the slide description spans, but I’m currently learning jQuery and Javascript for a fact, and I can’t get this one done by myself.
Btw, I managed to fix your IE7+ last slide image problem by adding a border:0 to the .image_reel img class because the images had default borders (for being anchors). A few users reported that the last image in the slide didnt show up. This’ll fix it for them.
On a future plan, I was planning to do a nifty job with the right thumb images. Lets say one user wants to have more than 4 images in the slide. I was thinking of doing some kind of vertical scroll-area where the thumbs currently are, by adding two arrows for manual scrolling (or automatic scrolling as) thus allowing the user to add practically unlimited images.
The current state of the project is located at: http://www.quicksave.ro/dev/build/slide/
Everything you need is there in its source.
So I had another take on the slide and managed to fix the bugs it had.
please check it out here: http://www.quicksave.ro/dev/build/slide_v2/
On another matter, I’m currently still accepting suggestions on how to create a vertical scroller from the right paging thumbs. Let’s say a user wants to have more than 4 images there. He should be able to add them, and the thumbs on the right will scroll down as necessary.
Any suggestions anyone?
I just have one question how do you start it a specified frame, as if I want to start it on the last Frame . The reason why is I’m adding DIV to the player and it works but it wont display the div childs on the first frame it does on the following frames. Any help would be great!
It’s very interactive. I really like like this, see the demo I was very impressed. I want to try it. Thank you for sharing information.
Daniel, my bet is to give that last frame a specific class/id and use the jQuery .find(“div .class_name_or_id_here”) function to have your way around with it.
I’m really more concerned about the issue in which a user wants to have endless images in the slide. Read my above comments to understand it better.
“Your Real Name”
Please tell me where to pud that code of yours for the FADE effect. I can;t get it to work :-(
Thanks!
My paging links won’t work :( -
Speak Your Mind...