2

I've got an image on my site, and everytime I click on that, it slides open a box with 4 links. The image starts at 0.6 opacity, and when you click on it to open the box, gets opacity 1. However I would like that when you close the box, the opacity goes back to 0.6.

My code is:

jQuery(document).ready(function() {
    jQuery('.toggle_hide').hide();
    jQuery(".moduletable span").css('cursor', 'pointer').click(function() {
        var $this = $(this);
        $this.css({
            opacity: '1'
        });         
        $('.toggle_hide').not($this.next("div")).fadeOut(300);
        $this.next("div").slideToggle(300);
    });
});

Hope you can help me out.

Best regards, Martin

1 Answer 1

1

Simply add a callback function on your fadeOut() to set the opacity back to 0.6 after the animation has completed:

$('.toggle_hide').not($this.next("div")).fadeOut(300, function() { 
    $this.css({opacity:'0.6'});
});
Sign up to request clarification or add additional context in comments.

8 Comments

+1, although the method signature is fadeout(duration, callback)
Hey James, Thanks alot for your assistance. I've tried adding that callback function to my fadeout, but now it seems like it skips the opacity change on the first click, as it remains on 0.6 opacity.
@user2882079 you have to remember that 300ms is a very short time (1/3 of a second). If you increase this to say 3000 (3 seconds) you'll notice the transition a bit easier. If you want to delay the opacity change, however, you can always use setTimeout. Wrap the $this.css(...) above in setTimeout(function() { $this.css(...) }, 1000) - the 1000 here is 1000ms (1 second).
Hey James. Think you misunderstood me. After I've added the code, the opacity never changes to 1 when I click on the image, like it did before.
The code that I've supplied doesn't change any of your existing code other than your fadeOut function. Are any JavaScript errors being thrown?
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.