【问题标题】:Show/hide animation显示/隐藏动画
【发布时间】:2016-06-04 21:33:11
【问题描述】:

我有一个问题,希望你们能帮助我。 请检查我的 jsfiddle > myFiddle

如果您单击“详细信息”按钮,您将通过一个简单的动画看到有关该项目的更多信息。 您可以通过单击左上角的“十字”图标来关闭此详细信息,您将看到关闭动画。

我的问题: 当当前项目(容器)详细信息打开(并且我没有使用“十字”图标关闭详细信息)时,如果我单击其他项目“详细信息”按钮,第一个项目(容器)详细信息没有隐藏(使用动画)。

如果有人能帮忙,那就太棒了

谢谢

jQuery('.btn.desktop').click(function(){
                jQuery('.btn.desktop.active').not(this).removeClass('active');
                jQuery(this).addClass('active');

                jQuery('.direction-container.active').not(this).removeClass('active');
                jQuery(this).addClass('active');


                // If button has class active
                if (jQuery('.btn.desktop').hasClass('active')) {

                    // If button is active add class active to direction container
                    jQuery(this).parent().closest('.direction-container').addClass('active');

                    // If direction container has class active
                    if (jQuery('.direction-container').hasClass('active')) {

                        // Show details container
                        jQuery('.direction-container.active').find('.details-desktop').fadeIn(500);


                        // Scroll down direction container after 500ms
                        setTimeout(function () {    
                            jQuery('.direction-container.active').animate({scrollTop: '100px'}, 500);
                        }, 500);

                        // Show close button
                        setTimeout(function () {
                            jQuery('.direction-container.active').parent().find('.close-details-desktop').fadeIn(500);  
                        }, 1000);



                        // Hide details container
                        jQuery('.direction-container.active').parent().find('.close-details-desktop').click( function() {
                            jQuery('.direction-container.active').animate({scrollTop: '0px'}, 300);
                            setTimeout(function () {    
                                jQuery('.details-desktop').fadeOut(300);
                                jQuery('.close-details-desktop').fadeOut(500);
                            }, 300);
                            setTimeout(function () {    
                                jQuery('.direction-container, .btn.desktop').removeClass('active');
                            }, 500);
                        });


                    } else {
                    }

                } else {
                }
                return false;
            });

【问题讨论】:

    标签: javascript jquery animation click show-hide


    【解决方案1】:

    您不会将它们淡出。

    jQuery('.direction-container.active').parent().find('.close-details-desktop').click( function() {
    

    这只会为活动容器按钮创建一个单击处理程序。它不会触发点击。此外,它不应该存在于另一个点击处理程序的深处,因为它只会在点击 .btn.desktop 后才会变为活动状态

    你的代码太复杂了,你自己很难。

    【讨论】:

    • 感谢您的回复。公平地说,我是 javascript 的新手。如果您能检查我的小提琴并进行正确的更改并保存,我将不胜感激如果您能帮助我,请告诉我
    • 当然可以帮助你。你知道函数是如何工作的吗?因为这可以大大简化你的代码
    猜你喜欢
    • 1970-01-01
    • 2012-02-25
    • 2016-02-02
    • 1970-01-01
    • 2010-11-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多