Skip to content

Instantly share code, notes, and snippets.

@randomutterings
Created February 15, 2009 15:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save randomutterings/64723 to your computer and use it in GitHub Desktop.
Save randomutterings/64723 to your computer and use it in GitHub Desktop.
Changing images with JQuery and the fade effect
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);
- @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