gpt4 book ai didi

jquery - addClass 事件到 slider 拇指

转载 作者:行者123 更新时间:2023-11-28 11:31:22 26 4
gpt4 key购买 nike

我正在尝试在单击 .thumb 时向 img 添加一个事件类。

我想做什么: enter image description here

我得到的: enter image description here

$(document).ready(function() {

$(".thumb").click(function() {
var IMG = $(this).find("img").addClass('active');
$(".viewer").not($(this).siblings().find('img').removeClass('active').parent().after()).remove();

var top = $(this).offset().top - 10;
// window.scrollTo(0, top); // no animation
$('html, body').animate({ scrollTop: top }, 100);

$(this).parent().after("<div class='viewer'><div class='content-slide'><img src='' /><p class='exit'>✖</p><h2></h2><span></span></div></div>");

$(".viewer").find("img").attr("src", IMG.attr("data-HD"));
$(".viewer").find("h2").text(IMG.attr("title"));
$(".viewer").find("span").text(IMG.attr("description"));
$(".content-slide img").height($(".viewer").height());
$("p.exit").click(function() {
$(this).closest(".viewer").slideUp(200, this.remove);
$("img").removeClass('active');
});
});

});

演示:http://codepen.io/anon/pen/NNrQWe

最佳答案

在您点击缩略图时删除类,

var IMG = $("img").not($(this).find("img").addClass('active')).removeClass("active");

DEMO

关于jquery - addClass 事件到 slider 拇指,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35955057/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com