Monday, November 23, 2009

jQuery: Shuffling Photo Gallery Tutorial

Creating a Shuffling Photo Gallery in jQuery is actually very simple. It's just a matter of calling timers("setIntervals()") and tweaking opacity.

Let's get started.

HTML
<div id="slideshow">
<img src="images/demo.png"/ class="active">
<img src="images/digg.png"/>
<img src="images/reddit.png"/>
<img src="images/twitter.png"/>
</div>
These are the images that you want to be shuffling.

CSS
<style type="text/css">
#slideshow{
text-align:center;
postion:relative;
}

#slideshow img{
position:absolute;
z-index:8;
top:0;
left:50%;
}

#slideshow img.active{
z-index:10;
}

</style>
We are gonna declare "position:absolute" for the images to stack up together.Z-index ensures that the "active" image will be on top of the rest.


Javacript
<script type="text/javascript">

$(document).ready(function(){
$('#slideshow img').animate({opacity:0.0},1);
$('#slideshow img.active').animate({opacity:1.0},1);
});

function slideSwitch(){
var $active = $('#slideshow IMG.active');
var $next = $active.next().length ? $active.next():$('#slideshow IMG:first');
$active.animate({left:'40%'},1000).animate({left:'50%'},1000).animate({opacity:0.0},500);
$next.addClass('active');
$next.animate({opacity:1.0},1000);
$active.removeClass('active');
}

$(function(){
setInterval("slideSwitch()",3000);
});
</script>

First, we hide all images except the active image.
$(document).ready(function(){
$('#slideshow img').animate({opacity:0.0},1);
$('#slideshow img.active').animate({opacity:1.0},1);
});


Next, our timer will call the function slideSwitch() every 3000 millisecond.
$(function(){
setInterval("slideSwitch()",3000);
});


In our slideSwitch function, we hook the active image into variable $active and the next awaiting image into $next.

var $next = $active.next().length ? $active.next():$('#slideshow IMG:first');

I found an excellent explanation from net-Tuts regarding the "?" above:

Think of everything before the question mark as being a question, if the answer to that question is true then execute the code to the left of the colon, but after the question mark. If the answer is false then execute the code after the colon.

The rest are just simple animation to mimic the shuffling action and also to reattach the active class to the images.

Labels: , , ,

62 Comments:

Blogger Digi Free said...

Thank you! Your blog post will be advertised on the DigiFree Tutorials search engine today (look for timestamp: 23 Nov [LA 04:00pm, NY 07:00pm] - 24 Nov [UK 12:00am, OZ 11:00am] ).

November 24, 2009 at 12:07 PM  
Anonymous Admin said...

Thanks Digi.

November 24, 2009 at 11:03 PM  
Anonymous Color Experts International said...

I have little knowledge about Jquery

March 4, 2010 at 6:39 PM  
Blogger International Manual Clipping Path said...

Thanks for this fascinating post. You are amazing!

October 1, 2010 at 4:31 PM  
Anonymous Admin said...

Your welcome. :)

October 24, 2010 at 1:03 PM  
Anonymous Buy Nexium 20 said...

Awesome tutorial. Thank you sharing :)

January 12, 2011 at 6:52 PM  
Anonymous Generic Viagra Online said...

You are amazing!

April 26, 2011 at 11:42 PM  
Anonymous company logo design said...

I need this article to complete my assignment in the college, and it has same topic with your article.

May 19, 2011 at 2:54 PM  
Anonymous Online Pharmacy said...

Great info! I recently came across your blog and have been reading along. I thought I would leave my first comment. I don’t know what to say except that I have enjoyed reading. Nice blog. I will keep visiting this blog very often.

July 1, 2011 at 12:31 PM  
Blogger alan said...

Thanks a lot for this awesome post.
keep working and posting variety
of articles...........


Smith Alan
generic viagra online

July 2, 2011 at 1:34 PM  
Anonymous android tablet said...

Good tutorial. I learnt a lot. Thanks for sharing.

July 13, 2011 at 8:44 AM  
Anonymous Generic Levitra said...

Shuffling photo gallery tutorial is very simple.j Query is a Java Script technology and programming.j Query is easy to learn.In j query some features are found such as-HTML elements, HTML events functions, Ajax ,CSS manipulations etc.

September 6, 2011 at 7:06 PM  
Anonymous 3d ultrasounds said...

These kind of post are always inspiring and I prefer to read quality content so I happy to find many good point here in the post, writing is simply great, thank you for the post...

September 14, 2011 at 3:06 PM  
Anonymous find doctor list said...

The blog is written in such a way that it is so easy to read and understand.

October 19, 2011 at 7:08 PM  
Anonymous Clipping Path Service said...

WOW! What a brilliant post. Thanks for sharing...

October 31, 2011 at 10:33 AM  
Anonymous Kamagra said...

Billige Viagra
Cialis Generika ist ein mit führenden Markenmedikamenten zu vergleichendes Potenzmittel Viagra, Cialis.

November 2, 2011 at 1:00 PM  
Anonymous Viagra said...

Acheter Viagra
De nos jours, Viagra est certainement un des médicaments les plus connus au monde. Même ceux qui n'ont jamais eu recours au Viagra le connaissent, et le médicament est désormais utilisé pour faire des blagues et le sujet principal d'histoires drôles.
Viagra Prix

November 2, 2011 at 1:40 PM  
Anonymous hcg said...

The post is very nicely written and it contains many useful facts. I am happy to find your distinguished way of writing the post. Now you make it easy for me to understand and implement. Thanks for sharing with us.

November 18, 2011 at 6:15 PM  
Blogger Online Photoshop Clipping Path, Masking Service said...

Really informative post. Like other people I have been benefited personally. Manythings were unknown to me what I have got here and learned
from.

April 9, 2012 at 2:01 PM  
Blogger Sonam Gupta said...

Take advantage of others' knowledge. In order to properly analyze and forecast price fluctuations you should have in-depth knowledge of the companies you invest in.

Stock Tips, Commodity Tips

May 31, 2012 at 7:56 PM  
Blogger Sonam Gupta said...

Look for companies that can grow and that should be able to remain profitable for the foreseeable future. Check to see how money is coming into their business.

Stock Tips, Commodity Tips

June 11, 2012 at 8:06 PM  
Blogger Stock Tips said...

Useful information shared. I am very happy to read this article. Thanks for giving us nice info. Fantastic walk through. I appreciate this post. Stock Tips

March 21, 2013 at 9:26 PM  
Blogger Attache Pr said...

It's very important for the web developers. Most of them face a problem with.

October 24, 2013 at 8:04 PM  
Blogger Clipping Path Job said...

This is obviously a nice help for us. It's a kind sharing of you.

December 18, 2013 at 5:29 PM  
Blogger clipping pathgenius said...

Clipping Path Genius (CPG) is one of the best quality clipping path service providers in the world. Clipping | path clipping | clipping paths | clipping service |masking|retouching retouching photograph| retouching photo| photo retouching| clipping path service provider

November 3, 2014 at 3:16 PM  
Blogger Bắp Cải said...

You have a real ability for writing unique content. I like how you think and the way you represent your views in this article. I agree with your way of thinking. Thank you for sharing.
unblocked games| unblocked games at school| unblocked games| friv4school| friv for school| friv games| frivgames| kizi2| kizi 2
unblockedgames| unblocked games at school| friv 4 school| friv4school| free online games| free online games| jogos da barbie| kizi

July 14, 2015 at 12:13 PM  
Blogger Love KidsTV said...

Thanks for your post. Click to play Plants vs Zombies , Solitaire,Tom And Jerry Games, Brain Games, Happy Wheels , Five Nights At Freddy's

September 22, 2015 at 11:01 PM  
Blogger thị hậu nguyễn said...

Great blog !! please visit my blog to learn more:
happy wheels
super mario bros
pacman
agario

October 22, 2015 at 10:19 AM  
Blogger rohit said...

happy new years eve images

happy new year 2016

Merry Christmas cards 2015

happy new year 2016 images


November 23, 2015 at 10:20 PM  
Blogger Gaurav Jain said...

Nice post Please have alook on this

New Year 2016
Happy new year Sms 2016
Happy New Year 2016 Quotes

December 3, 2015 at 3:18 PM  
Blogger Pants Fancy said...

I feel your sharing interesting. If you feel tension in your work, then you try to play our FREE. Thank you !
fancy pants 3
fancy pants
fancy pants 4
fancy pants 2
fancy pants 5
fancy pants 3 game
fancy pants 3 hacked
fancy pants 3 unblocked
fancy pants adventure 3
fancy pants adventure

December 11, 2015 at 4:05 PM  
Blogger Gaurav Jain said...

Nice post Please have alook on this

New Year Images 2016
Happy New Year Quotes 2016
Happy New Year SMS 2016 images

December 20, 2015 at 12:30 AM  
Blogger clippingpathsaffron said...

Your Tutorials is beautiful.you are using that is very useful and helpful.Thanks for sharing

March 13, 2016 at 1:39 AM  
Blogger Ann Kelly said...

Thank you! I have to thank you for the efforts you’ve put in penning this site.I really hope to check out the same high-grade blog posts by you later on as well. In truth, your creative writing abilities has motivated me to get my own website now !
I like play games. Click to play:
open facebook
facebook login
happy wheels
happy wheels game
earn to die
earn to die game

March 31, 2016 at 4:18 PM  
Blogger Cherry winter said...

Age of War

In this game, you start at the cavern men's age, then evolve! There is a total of 5 ages, each with its units and turrets. Take control of 16 different units and 15 different turrets to defend your base and destroy your enemy.
Age of War

Age of War 2

April 1, 2016 at 9:41 AM  
Blogger Ann Kelly said...

Written, Thank you for the introduction of a range of information that is very interesting to see in this article.
Signature: open facebook | facebook login | happy wheels | happy wheels game | earn to die | earn to die game
I enjoyed over read your blog post. Your blog have nice information, I got good ideas from this amazing blog. I am always searching like this type blog post. I hope I will see again..

April 6, 2016 at 9:54 AM  
Blogger Jordan Ovilia said...

Earn to Die Description
Earn to Die sees you not only driving your way through hordes of zombies, but allows you to earn cash to upgrade, unlock and customise new vehicles. Is your vehicle not strong enough? Why not add a gun, or boosters, or even a spiked frame?
earn to die

tank trouble

you get to truly showcase your skill against a wide range of human and AI as you see fit.
With Tank Trouble 3, you don’t have to worry about deadlines nor anything like that, instead this is a fun, relaxing game that you can play whenever you want without any restrictions. It’s really nice and fun to enjoy your time when all you have to do is to destroy the other tanks in the game world. And since the game world is continually changing, offering you more insane challenges, it’s a lot more fun and exciting to explore all of these possibilities in an outstanding way.

tank trouble 3

April 6, 2016 at 4:38 PM  
Blogger Cherry winter said...

Age of War

In this game, you start at the cavern men's age, then evolve! There is a total of 5 ages, each with its units and turrets. Take control of 16 different units and 15 different turrets to defend your base and destroy your enemy.
Age of war 1,2,3,4,5,6


Summon creatures to fight enemy units and demolish the opposing castle. Your castle is equipped with a crossbow, which you can use to shoot enemies. Make sure you upgrade skills to increase your chances of winning battles.
Age Of War play free online Games


The war between humans, orcs and elves continues. Lead your race through a series of epic battles, using your crossbow to fend off foes and sending out units to destroy castles. Researching and upgrading wisely will be crucial to your success!
Age Of War online


Play Age of war 2! Battle your opponent through the ages, in the 2nd installment of the hit game Age Of War. Age of war 2 is totally free and requires no registration!
Age Of War 2


This is an evolutionary strategy game that pits you against alien invaders. You begin the game in the Stone Age, with just a base and some money. Select your base to view the available building options and spend your money wisely. Buy buildings that will spawn offensive units and gatherers, as well as turrets to bolster your defenses. You can upgrade your buildings so that they produce more effective units and spawn them at a faster rate.
Age Of War

April 11, 2016 at 6:22 PM  
Blogger Alice Denny said...

Thanks for sharing nice information with us. i like your post and all you share with us is uptodate and quite informative, i would like to bookmark the page so i can come here again to read you, as you have done a wonderful job.
Play Earn to Die Online

This article always blew me... For how many times I have read this. The overwhelming feeling never changes.
Earn to Die Games

April 12, 2016 at 5:44 PM  
Blogger Lisa Henry said...

We are really grateful for your blog post. You will find a lot of approaches after visiting your post. Great work.
Strike Force Heroes Game
|Strike Force Heroes1
Is a new game action-packed shooter from the creators of Raze; with 3 game modes, 15 campaign missions and over 65 weapons.
Strike Force Heroes2
|Strike Force Heroes3
In the second installment of the action-packed shooting game you have to take over your enemy space base at all costs.
Strike Force Heroes4
Once you finished to kill all the enemies or to take all their flags the mission will be completed and you will be abletounlock another mission.
HOTMAIL SIGN IN
The process of creating your Hotmail account has been successful, you can use it right now
GMAIL LOGIN BLOG
.Good luck!

April 12, 2016 at 5:45 PM  
Blogger Jordan Ovilia said...

Earn to Die Description
Earn to Die sees you not only driving your way through hordes of zombies, but allows you to earn cash to upgrade, unlock and customise new vehicles. Is your vehicle not strong enough? Why not add a gun, or boosters, or even a spiked frame?
earn to die801

Earn to Die 3 is one of those titles that you need to look at with complete …
earn to die473

you get to truly showcase your skill against a wide range of human and AI as you see fit.
With Tank Trouble 3, you don’t have to worry about deadlines nor anything like that, instead this is a fun, relaxing game that you can play whenever you want without any restrictions. It’s really nice and fun to enjoy your time when all you have to do is to destroy the other tanks in the game world. And since the game world is continually changing, offering you more insane challenges, it’s a lot more fun and exciting to explore all of these possibilities in an outstanding way.

earn to die9561

Play Earn to Die 2: Unlock and upgrade vehicles and more vehicular zombie slaughter than ever
.
earn to die961
Earn to Die has been one of those games that has been remarkably popular, having hung around the top charts for a long, long time now. Here you can play the first game – Earn to Die 1.

earn to die592


April 12, 2016 at 6:18 PM  
Blogger maika lee said...

Thanks for the best blog.it was very useful for me.keep sharing such ideas in the future as well.this was actually what i was looking for,and i am glad to came here!
earn to die
Hi! I’ve been reading your blog for a while
now and finally got the courage to go ahead and give youu a shout out from Austin Texas! Just wanted to tell you keep up the fantastic work!my weblog:
tank trouble
tank trouble

earn to die 1

April 14, 2016 at 10:29 AM  
Blogger Mai Doan said...

The Big Head Soccer synthetic Big Head Football games famous. on head soccer you could be playing head soccer unblocked , big head basketball or Big Head Soccer. Big Head Soccer Big Head Football big head basketball big head basketball are games is our top. Rejoice with Big Head Soccer Big Head Football Big Head Football big head basketball offline

April 26, 2016 at 3:38 PM  
Blogger hường lê said...

We are really grateful for your blog post. You will find a lot of approaches after visiting your post.

Great work.

Such a very useful article. Very interesting to read this article.I would like to thank you for the

efforts you had made for writing this awesome article.
Sign in to Gmail to access to all Gooogle services. Log in to your account or sign up to create a new

account
gmail sign in

gmail log in

what's gmail?

slitherio

Tank trouble

happy wheels

Strike Force Heroes

In this game, you start at the cavern men's age, then evolve! There is a total of 5 ages, each with its

units and turrets. Take control of 16 different units and 15 different turrets to defend your base and

destroy your enemy.
age of war

We are really grateful for your blog post. You will find a lot of approaches after visiting your post.

Great work.
happy wheels

strike force heroes

earn to die

Fireboy and Watergirl arrived again to the temple in the forest. 2 players together can help them to find

their way out.
fire boy and water girl

May 30, 2016 at 11:15 AM  
Blogger Regina Hilary said...

The war between humans, orcs and elves continues. Lead your race through a series of epic battles, using your crossbow to fend off foes and sending out units to destroy castles. Researching and upgrading wisely will be crucial to your success!
age of war 3 | age of war 2 | unfair mario 2 | tank trouble 3 | tank trouble
The game controls are shown just under . Movement mechanisms primarily include acceleration and tilting controls.
cubefield | tank trouble | happy wheels | slitherio | gold mine

This app is great it gives you those moments of relaxation and incredibly wonderful
earn to die 1 | earn to die 2 |
earn to die 3 | earn to die 4

June 16, 2016 at 4:56 PM  
Blogger NextG Design said...

Very nice tutorial. Well explained & easy to learn to crate an idea. Thanks for share this wonderful post. :)

June 20, 2016 at 4:25 PM  
Blogger Alice Denny said...

Welcomes to google terminal from Austin Texas! google snake
Amazing insight you have on this, Happy wheels it's nice to find a website that details so much information about different artists... Age of war 2 This article always blew me... Earn to die For how many times I have read this.
slither io Hi! I’ve been reading your blog for a while slitherio it's nice to find a website that details so much big farm

June 23, 2016 at 11:39 AM  
Blogger Soc Cute said...

With a Hotmail account, you can send and receive emails quickly and easily as well as login and use all Microsoft services.
gmail sign in | gmail login
sign in to hotmail | log in to hotmail

This is the game is played so great. Invite you to experience it interesting things there.
strike force heroes 4 | red ball | slitherio
gun mayhem 2 | can your pet | happy wheels

August 8, 2016 at 10:44 AM  
Blogger Candy Sim said...

All the best blogs that is very useful for keeping me share the ideas
of the future as well this is really what I was looking for, and I am
very happy to come here. Thank you very much
earn to die 3
game hot earn to die 3
Hi! I’ve been reading your blog for a while now and finally got the courage to go ahead and give youu a shout out from Austin Texas! Just wanted to tell you keep up the fantastic work!my weblog
game hot tank trouble 3
game tank trouble

August 11, 2016 at 5:30 PM  
Blogger clippingcare said...

I dont know much about jquery and its helpful for me.
clipping path |clipping path service
clipping path services |back ground removing service




August 20, 2016 at 2:11 PM  
Blogger Cute Soc said...

To join the free games you go here. It will have a lot of great games for you that
gun mayhem 3 | can your pet 2
learn to fly 3 | happywheels
tank trouble 3

September 17, 2016 at 10:30 AM  
Blogger Giải Trí Tổng Hợp said...

The blog or and best that is extremely useful to keep I can share the ideas. Age Of War 2
Big Farm | Slitherio | Tank Trouble
Of the future as this is really what I was looking for, I am very comfortable and pleased to come here. Thank you very much.
Happy Wheels | Goodgeme Empire | Slither.io


November 3, 2016 at 9:44 AM  
Blogger Candy Sim said...


All the best blogs that is very useful for keeping me share the ideas
of the future as well this is really what I was looking for, and I am
very happy to come here. Thank you very much
stick war 2| gold mine strike |animal jam 2 | shooting games |
|stickman games|animal jam 2 |kids games free | games games |animal jam codes

November 3, 2016 at 10:57 AM  
Blogger Cute Soc said...

To be able to participate in free online games. You can click here to play always.
gun mayhem | can your pet
learn to fly | happy wheels
tank trouble 3

November 5, 2016 at 12:24 PM  
Blogger Alice Denny said...

The blog or and best that is extremely useful to keep I can share the ideas. Age Of War 2
Big Farm | Slitherio | Tank Trouble
Of the future as this is really what I was looking for, I am very comfortable and pleased to come here. Thank you very much.
Happy Wheels | Goodgeme Empire | Slither.io


November 23, 2016 at 10:35 AM  
Blogger hường lê said...

Such a very useful article. Very interesting to read this article.I would like to thank you for the efforts you had made for writing this awesome article.

Discover our website bounty of free online games now!
Our website has the biggest collection of free online games. Totally new games are added every day!

age of war 2| gold Miner 2| unfair Mario 2 | cubefield 2 |tanki Online 2

November 24, 2016 at 12:04 AM  
Blogger Clipping Path said...

I am really benefit from your Tutorials . I hope, some Tutorials get better futures.Thank you so much dear.

November 28, 2016 at 9:06 PM  
Blogger Clipping Path said...

This comment has been removed by the author.

November 28, 2016 at 9:10 PM  
Blogger ILHAM SURYA PRATAMA said...

good job and I like it. great post and it is very beneficial.


visit mp3z.logdown.com for more KPOP Single,KPOP Album and KPOP OST

February 11, 2017 at 2:39 PM  
Blogger Linda Rose said...

Very interesting! Thanks for your sharing
usps tracking

March 20, 2017 at 6:10 PM  
Blogger Linda Rose said...

It is a great article. You will surely like this also because it is a great stufff
Facebook Lite

March 22, 2017 at 11:54 AM  
Blogger Abigail Bukai said...

What's happening, good web site you have got going here
http://mymedicalfinds.com/antabuse-online.html

July 15, 2017 at 4:57 AM  

Post a Comment

Subscribe to Post Comments [Atom]

Links to this post:

Create a Link

<< Home