Brent
Brent

Reputation: 2485

FadeIn Fadeout Function Jquery

I have created two functions to accept mutiple class's and Ids to fadein and fadeout, currently it will fadeout elements fine but not fadein?

function fadeOut($element, cb) {
    $element.animate({opacity:0}, 800, function(){
        if (cb) cb();
    });
}

function fadeIn($element, cb) {
    $element.animate({opacity:1}, 800, function(){
        if (cb) cb();
    });
}

Example input

$("#back").click(function () {
    fadeOut($('.hideToggle, .history, .apphome, .stats, #back'));
});
$("#open").click(function () {
    fadeIn($('.hideToggle, .history, .apphome, .stats, #back'));
});

Upvotes: 0

Views: 236

Answers (3)

Tuhin
Tuhin

Reputation: 3373

USe This:

$("#back").click(function () {
    $('.hideToggle, .history, .apphome, .stats, #back').fadeOut();
});
$("#open").click(function () {
    $('.hideToggle, .history, .apphome, .stats, #back').fadeIn();
});

Upvotes: 0

Ron van der Heijden
Ron van der Heijden

Reputation: 15070

You say you want to fadein and fadeout?

I gues you want a toggle?

$("#back, #open").click(function () {
    $('.hideToggle, .history, .apphome, .stats, #back').fadeToggle();
});

http://jsfiddle.net/Rcw93/

Or if you want to controll them apart you can use:

$("#back").click(function () {
    $('.hideToggle, .history, .apphome, .stats, #back').fadeOut();
});
$("#open").click(function () {
    $('.hideToggle, .history, .apphome, .stats, #back').fadeIn();
});

http://jsfiddle.net/Rcw93/1/

Upvotes: 2

Shakesy
Shakesy

Reputation: 335

Use $(this).fadeIn() or fadeOut() you cannot fade in and out at the same time, you can however do one after the other using the callback function.

Upvotes: 0

Related Questions