Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript jQuery Basics (2014) Creating a Simple Lightbox Perfect

Rifqi Fahmi
Rifqi Fahmi
23,164 Points

improve overlay

I want to make the image show up slow and when I close the image it also do the same. I have code

var overlay = $("<div id='overlay'></div>");
var image = $('<img>');

overlay.append(image.hide());
$('body').append(overlay);



$('#gallery a').click(function(event) {
    event.preventDefault();
    var imageLocation = $(this).attr('href');
    image.attr('src', imageLocation)
    image.css('width: 200');
    overlay.show();
    image.show('slow');


    });

overlay.click(function() {
    overlay.hide().ready(image.hide('slow'));

    });

when I click the image open with slow but when I close the image, the slow effect didn't affect the image. how to fix this.

thanks :)

3 Answers

overlay.click(function() {
    overlay.hide('slow').ready(image.hide('slow'));

    });
Rifqi Fahmi
Rifqi Fahmi
23,164 Points

nope, it will make the overlay disappear slowly. all I want are the image disappear slowly first then the overlay disappear without slow effect. hmmmmmm

You might have to separate the image hide and overlay hid functions. However, just another JS noob here. :)

Rifqi Fahmi
Rifqi Fahmi
23,164 Points

btw thanks for answering. me too here :)