javascript - 按下辅助按钮时关闭按钮上的事件状态

标签 javascript jquery html css

我在关闭页脚按钮的事件状态时遇到问题。当您单击 footer 时,它会滑动一个隐藏的 div,将 fix div 向上推,并将 footer 更改为关闭,并为其事件状态设置背景颜色。单击关闭后,div 将向下滑动,文字将变回页脚,事件状态将隐藏。

问题

当我单击菜单按钮时,它不会更改页脚按钮上的事件状态。 div 会向下滑动,但文字不会从 close 变为 footer,背景颜色也不会改变。

JS

$('#more').click(function () {
    var open = $('header').is('.open');
    $('#footerPanel')['slide' + (open ? 'Up' : 'Down')](400);
    $('header').animate({
        bottom: (open ? '-' : '+') + '=120'
    }, 400, function () {
        $('header').toggleClass('open');
    });                 
});
$('#menu').click(function () {
    if ($('header').is('.open')) {
        $('header').removeClass('open').animate({'bottom': "-=120"});
        $('#footerPanel').slideUp(400);
    }
});
$('.footerButton').click(function(){
    var $this = $(this);
    $this.toggleClass('footerButton');
    if($this.hasClass('footerButton')){
        $this.text('Footer');           
    } 
    else 
    {
        $this.text('Close');
    }
    $(this).toggleClass('activetoggle');
});

我的 Fiddle . 我该如何解决这个问题?

最佳答案

我添加了以下函数作为单击菜单按钮时 animate 函数的回调。它将检查页脚按钮是否处于事件状态,如果是,将进行相应更新,否则将保持不变。

function () {
    var $footer = $('.activetoggle');

    if ($footer.length)
        $footer
            .toggleClass('activetoggle footerButton')
            .text('Footer');
}

Updated Fiddle

关于javascript - 按下辅助按钮时关闭按钮上的事件状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21117630/

相关文章:

javascript - angularjs 1折叠具有不同内容的同一面板

javascript - 我的递归函数(javascript)总是返回 false,即使它是 true

javascript - 单击链接并重定向时如何添加事件类?

html - 设置长度右边框

html - 像在歌曲簿中一样自定义上标

html - 为了可重用性,在不同的类中提取 css 有什么缺点吗?

javascript - 如何在页面准备好之前通过 javascript 加载外部字体

javascript - Z-index 阻止 gif 动画的运行 | Jquery CSS HTML JS

javascript - JQuery关于mouseup事件的问题

javascript - jquery - css 在 .after() 之后不起作用