gpt4 book ai didi

javascript - if 语句卡在 else

转载 作者:太空宇宙 更新时间:2023-11-03 20:13:20 24 4
gpt4 key购买 nike

我试图通过单击同一个词来使菜单出现和消失。我刚开始学习这些语言。但我认为我正在取得一些进展。在这里和其他在线资源上阅读了大量内容后,我发现了这一点:

var main = function() {

if($('.menu').css('top') == '-65px') {
$('.icon-menu').click(function() {
$('.menu').animate({top: '10px'}, 400);
$('.content').animate({top: '10px'}, 400);
});
}

else {
$('.icon-menu').click(function() {
$('.menu').animate({top: '-65px'}, 400);
$('.content').animate({top: '-65px'}, 400);
});
}
};

$(document).ready(main);

到目前为止,我能够使菜单出现但不会消失。

谁能帮帮我?

最佳答案

您只检查一次菜单的状态,而不是在每次点击时检查。把东西翻过来:

var main = function() {
$('.icon-menu').click(function() {

if ($('.menu').css('top') == '-65px') {
$('.menu').animate({top: '10px'}, 400);
$('.content').animate({top: '10px'}, 400);
}
else {
$('.menu').animate({top: '-65px'}, 400);
$('.content').animate({top: '-65px'}, 400);
}
});
};

关于javascript - if 语句卡在 else,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26853711/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com