2

当我单击任何年份列(2012、2011、2010 等)时,它会显示每年的内容并隐藏其他年份。

问题是当我点击(例如 2011 年专栏)时,动画会同时完成所有效果,让用户感到困惑,我想我必须用动画步骤来做,但我一直没能找到jQuery 解决方案。

这是我的代码:

/* Scroll Function */
function scrollto(position){
    $('html, body').stop().animate({
        scrollLeft: position
    }, 1000);
}

/* Calendar Scroll */
$(".sub_section_title").click( function(e) {
    e.preventDefault();
    $(".contenido_calendario").hide();
    $(this).next(".contenido_calendario").toggle('slow');
    scrollto($(this).offset().left - 352)
});

我曾尝试通过使用 .queue() 来修复效果,但它不起作用,我不知道它的代码是否也写得很好:

$(".sub_section_title").click( function(e) {
    e.preventDefault();
    $(".contenido_calendario").hide();
    $(".contenido_calendario").queue(function() {
        scrollto($(this).offset().left - 352);
        $(this).dequeue();
    });
    $(".contenido_calendario").queue(function() {
        $(this).next(".contenido_calendario").toggle('slow')
    $(this).dequeue();
    });
});

动画应该是:单击 2011 > 向左滚动 2011 列(隐藏 2012 内容) > 显示内容动画

4

1 回答 1

2

您想利用 jQuery 动画的回调功能。例如,对于hide ,您可以执行以下操作:

var outerContainer = $(this);
$(".contenido_calendario").hide(500, function() {
    outerContainer.next(".contenido_calendario").toggle('slow', function() {
        scrollto(outerContainer.offset().left - 352);
    });
});

这将确保动画在前一个完成时运行。

于 2012-10-18T13:47:38.057 回答