【发布时间】:2013-05-09 23:30:07
【问题描述】:
我的动画有一个奇怪的(又一次)问题。
简而言之,我有一张图片,当我点击它时,会出现两个 div,并且有一个关闭按钮可以删除这些 div。但是当我点击那个按钮时,只有一个 div 消失了。
两个新的 div 有一个调试类,当我点击按钮时我通常会删除它
$('#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');
});
您可以在此处查看实际操作:http://www.jeremybarbet.com/effect/bug.html
【问题讨论】:
-
我没有看到关闭按钮。可以发jsFiddle吗?
-
这是因为您的 this.parents().eq(3) 没有针对正确的 div - 如果您单击按钮,活动类仍然保留在我猜您要删除的目标上类来自
-
@MarioDeSchaepmeester 有在线版,点击图片后出现关闭按钮。
-
@Pete 但是,当我点击关闭按钮时,右侧的 div 消失了,活动的类也被删除了,只有 .info-texte 总是在这里。
-
在上面的示例中,如果您检查元素 - li,单击按钮后活动类仍然存在 - 为什么不尝试使用
.parents('li.active')
标签: javascript jquery css css-animations