我已经在 HTML 4x2 中布置了一些图像。我的脚本目前正在使用 .addClass() 放大每张图片,但只会在图库中的第一张图片上使用 .removeClass()。
我如何才能将 .removeClass() 应用于每张图片? - 这是我的代码:
$(document).ready(function () {
$('#fig').delegate('img', 'click', function () {
$(this).addClass("imgbig");
$('.xbutton').stop(true, true).fadeTo(800, 1);
$("#fig").stop(true, true).addClass("f1");
});
$('.xbutton').click(function () {
$('#imgSmall').removeClass("imgbig");
$('.xbutton').stop(true, true).fadeOut(800, 0);
$("#fig").stop(true, true).removeClass("f1");
});
});
最佳答案
在这里$('#imgSmall').removeClass("imgbig")
你选择了id为imgSmall
的图片,而不是你所有的图片。
我想你应该像下面这样重写你的回调:
$('.xbutton').click(function(){
$(".imgbig").removeClass("imgbig");
$('.xbutton').stop(true, true).fadeOut(800, 0);
$("#fig").stop(true, true).removeClass("f1");
});
关于javascript - .removeClass() 只工作一次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31996164/