【发布时间】:2014-06-18 22:15:11
【问题描述】:
我有一个图像...我想要什么:当我点击它时,它应该被放大并且应该添加一个名为“close”的类。因此,当我再次单击它时,图像应调整为其原始大小,并且我想在可以再次单击它以增长的同时删除该类... 我成功添加了一个类,但我无法删除它。
HTML:
<div class="intro-img">
<img src="uploads/images/2.jpg" alt="Sensuality 1" />
</div>
CSS:
.intro-img {
position: relative;
display: block;
height: 80%;
max-width: 80%;
margin: 5% auto;
}
.intro-img img {
height: 100%;
max-width: 100%;
cursor: pointer;
-webkit-transition: all 0.5s ease;
-moz-transition: all 0.5s ease;
-ms-transition: all 0.5s ease;
-o-transition: all 0.5s ease;
transition: all 0.5s ease;
}
.intro-img img:hover {
height: 105%;
max-width: 105%;
}
脚本:
$('.intro-img img').click(function(){
$('.intro-img img').addClass( 'close');
$('.intro-img').animate({'height':'100%','max-width':'100%','margin': '0 auto'}, 500, 'easeInCirc');
});
$('.intro-img .close').click(function(){
$('.intro-img').animate({'margin': '5% auto','height':'80%','max-width':'80%'}, 500, 'easeInCirc');
$(this).removeClass('close');
});
如何通过第二次点击删除“关闭”类?我的脚本有什么问题? (我读过一篇关于它的帖子here,但我不能用它来处理我的情况)
【问题讨论】:
标签: jquery removeclass