简体   繁体   中英

jQuery for clicking on a button which fades out one div and then fades in another and then to do it in reverse

How do you write jQuery for clicking on a button which fades out one div and then fades in another and then clicking another button that does the reverse.

I am really stuck at the half way mark. With the code below I am able to fade out the div and fade in another but unsure on how to do the opposite.

Could really do with your expert help on this task. Would be much appreciated - thanks.

$(document).ready(function() {
    $('#triggerButton1').click(function(e){
        $('#homepagetext').fadeOut('slow', function(){
            $('#contactform').fadeIn('slow');
        });
    });
    $('#triggerButton2').click(function(e){
        $('#contactform').fadeOut('fast', function(){
            $('#homepagetext').fadeIn('slow');
        });
    });
});

Your code seems to be working fine in a fiddle: https://jsfiddle.net/05q2m4to/
The only thing that seems weird to me is having one fade go fast and all the other ones slow but that doesn't break anything.

Maybe the problem is somewhere outside the script?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM