0

I have a weird (one more time) issue on my animation.

In a nutshell, I have a picture, when I clicked on it, two div appears, and there is a close button to remove those divs. But when I click on that button, there is only one div who dissapears.

The two new divs have got a debug class and I normally remove it when I clicked on the button

$('#gallery').on('click', 'li', function(e) {

        // To display the animations with position
        var $this = $(this),
            dataItem = $this.data('item');

        // Left animation
        if ( dataItem == 1 ) {
            console.log( $this );

            $this
                .addClass('active')
                .find('.info-texte')
                    .removeClass('hidden')
                    .addClass('debug');

            // When animation is ended add the second part
            $this.find('.debug').on('animationend webkitAnimationEnd oAnimationEnd MSAnimationEnd', function() {
                $this.find('.info-btn')
                    .removeClass('hidden')
                    .addClass('debug');
            });
        }

        // Supprime le href event
        e.preventDefault();
    });

    $('.btn-close').on('click', function() {
        var $this = $(this);

        $this
            .parents()
            .eq(3)
                .removeClass('active')
                .find('.info-texte, .info-btn')
                    .removeClass('debug')
                    .addClass('hidden');
    });

You can see in action right here : http://www.jeremybarbet.com/effect/bug.html

4

2 回答 2

1

根据我的评论,您 $this.parents().eq(3)的目标是错误的元素

如果你把它改成$this.parents('li.active')

你的两个 div 都应该消失:

http://jsfiddle.net/TDsCT/

编辑

经过仔细检查,这是因为您的点击:

$('#gallery').on('click', 'li'

当您单击按钮时,这也会触发,因为按钮位于您的#gallery li. 我已经更改了您的代码,因此您单击图像而不是打开,然后单击您的按钮关闭:

http://jsfiddle.net/TDsCT/5/

于 2013-05-09T14:36:52.057 回答
0

似乎表达式 $this.parents().eq(3) 没有评估您想要的结果——左边的两个 div。也许尝试一组不同的 DOM 遍历方法?(例如 $this.parents().eq(2).prev() 和 $this.parents().eq(2),虽然这有点杂乱无章)

于 2013-05-09T14:04:29.480 回答