Today we are going to learn how to use jQuery's animate() method in order to create a sliding caption for the image, which will be triggered when the hover() event occurs.
JavaScript Tutorial
Time: 12:03 min / Price: £0.00
Sebastian Sulinski on 19th Jul 2011




Linus on Tuesday, 14th February 2012
Hi!
Thank you for this tutorial. Exactly what I was looking for.
The caption slider works perfect:) but I seem to have two little problems with it. I have linked my image (where I have the caption) to Shadowbox and Shadowbox is executed if I click on the image itself but It doesn't work if I click on the caption...can this be solved?, because I want to have a "click me" link on the caption. Now I have to move my cursor from the caption to the image and then click. And is it possible to setup a link (http://...) on the caption? If so, how do I do that?
Best regards
canaan77
Reply
Sebastian Sulinski : @designtutorials on Wednesday, 15th February 2012
Hi Linus,
To have the caption as link you could add another attribute to the li tag called for instance data-url:
Then amend the code like so:
var arr = $('#images li'); $.each(arr, function() { var thisUrl = $(this).attr('data-url'); if (thisUrl !== '') { $(this).append( '<a href="' + thisUrl + '" class="caption">'+$(this).find('img').attr('alt')+'</a>' ); } else { $(this).append( '<span class="caption">'+$(this).find('img').attr('alt')+'</span>' ); } }); $('#images li').hover(function() { $(this).children('.caption').stop().animate({ top : '100px' }, 200); }, function() { $(this).children('.caption').stop().animate({ top : '200px'}, 200); });Reply