Created
February 15, 2009 15:23
-
-
Save randomutterings/64723 to your computer and use it in GitHub Desktop.
Changing images with JQuery and the fade effect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function addClickHandlers(){ | |
// Adds click handlers to image thumbnails that update the larger image | |
$("img.thumbnail", this).click(function() { | |
src = this.src.replace("small", "medium") | |
$("#medium_photo").fadeOut(200, function(){ | |
$("#medium_photo").attr('src',src).bind('readystatechange load', function(){ | |
if (this.complete) $(this).fadeIn(400); | |
}); | |
}); | |
}); | |
}; | |
$(document).ready(addClickHandlers); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- @listing.photos.each do |p| | |
= image_tag(p.photo.url(:small), :class => "thumbnail") | |
= image_tag(@listing.photos.first.photo.url(:medium), :id => "medium_photo") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment