6

I want to have two buttons, one to fade div1 out, and one either to fade div1 in, or to fade out the button itself, if the div1 is already hidden. here's the code, pretty unnecessary though, cause my main problem is "if" statement...

$('#b > button').click(function(){
    $('#div1').fadeOut(400)
});

$('#div2 > button').click(function(){
    $('#div1').fadeIn(400)
});
4

2 回答 2

20

FadeOut 只是将 更改displaynone.

$('selector').css('display')使用 jQuery或检查显示是否无$('selector').is(':visible')

于 2012-12-28T21:41:18.987 回答
3

为什么不禁用/启用按钮?

$('#b > button').click(function(){
    $('#div1').fadeOut(400, function() {
        $(this).prop('disabled', true);
        $('#div2 > button').prop('disabled', false);
    });
});

$('#div2 > button').click(function(){
    $('#div1').fadeIn(400, function() {
        $(this).prop('disabled', true);
        $('#b > button').prop('disabled', false);
    });
});
于 2012-12-28T21:52:10.107 回答