System-x32z
System-x32z

Reputation: 1971

Slideshow buttons - jquery

I have this very simple slideshow here: http://jsfiddle.net/Jtec5/
Here's the codes:
HTML:

<div id="slideshow">
   <div>
     <img src="http://farm6.static.flickr.com/5224/5658667829_2bb7d42a9c_m.jpg">
   </div>
   <div>
     <img src="http://farm6.static.flickr.com/5230/5638093881_a791e4f819_m.jpg">
   </div>
   <div>
     <img src="http://gillespaquette.ca/images/stack-icon.png">
   </div>
</div>

CSS:

#slideshow { 
    margin: 50px auto; 
    position: relative; 
    width: 240px; 
    height: 240px; 
    padding: 10px; 
    box-shadow: 0 0 20px rgba(0,0,0,0.4); 
}

#slideshow > div { 
    position: absolute; 
    top: 10px; 
    left: 10px; 
    right: 10px; 
    bottom: 10px; 
}

Jquery:

$("#slideshow > div:gt(0)").hide();

setInterval(function() { 
  $('#slideshow > div:first')
    .fadeOut(1000)
    .next()
    .fadeIn(1000)
    .end()
    .appendTo('#slideshow');
},  3000);

You can see in the slideshow there's buttons that tells me in which photo I am, I'm trying to relate every button with its photo so when I click it it takes me to its photo, if changing the whole code of the button is needed it will be better because I didn't like my code, I think it's too long.

Upvotes: 1

Views: 230

Answers (1)

maverickosama92
maverickosama92

Reputation: 2725

try following:

$('#slideshow div').children("img").on("click",function(){
  //you can use this source to open image either in iframe or dialog its your choice
  var src = $(this).attr("src"); 
});

working fiddle here: http://jsfiddle.net/Jtec5/30/

Upvotes: 1

Related Questions