javascript - 缩放浏览器时如何向下滑动 jQuery slideToggle

标签 javascript jquery html css

我的 slideToggle 函数有问题。一旦按下它就会打开我需要的方式。但是当我缩放浏览器以测试站点的响应流时,slideToggle 仍然保持事件状态而不是向下滑动。我尝试了一些功能,但似乎没有任何效果。下面是我在没有代码的情况下使用的脚本,当它到达特定的屏幕分辨率时向下滑动。我将如何解决这个问题?

$('#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"
    }, function () {
        var $footer = $('.activetoggle');

        if ($footer.length) 
            $footer
                .toggleClass('activetoggle footerButton')
                .text('Footer');
    });
    $('#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');
});

我的代码

http://jsfiddle.net/wyze/XqUp4/4/

最佳答案

试试这是否适合您。我添加了检查宽度是否为780(您可以更改它),当面板向下滑动时。尝试在你的 fiddle 中添加这个并检查它是否有效

$(window).resize(function(){ //check when window resize
if($(window).width() < 780){ // check when the window width is less than 780 
    if ($('header').is('.open')) { 
        $('header')
            .removeClass('open')
            .animate({
            'bottom': "-=120"                
        });
        $footer = $('.activetoggle');
        if ($footer.length) {
             $footer.toggleClass('activetoggle footerButton').text('Footer');
        }
        $('#footerPanel').slideToggle(400);
    }
}
});

关于javascript - 缩放浏览器时如何向下滑动 jQuery slideToggle,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22507993/

相关文章:

javascript - 在编写 SVG animateTransform 脚本时使用变量?

javascript - Google map V3 GSize 已更改

javascript - 显示/隐藏搜索 Div Angular UI

javascript - 焦点事件不适用于动态内容

jquery - 将 jQuery 类更改绑定(bind)到点击视口(viewport)顶部的 div ID?

jquery - 将完整日历右标题从按钮更改为列表项

css - 如何获得img垂直居中?

Javascript 对象字面量、POST 问题

php - 将 PHP 文件中的 HTML 转换为 PDF 文件

javascript - 如何设置从 Page1.html 到 Page2.html 的特定页面转换?