(function () { function setConDivHeight() { var actualHeight = $("#con_div") && $("#con_div")[0] && $("#con_div")[0].scrollHeight; var newHeight = actualHeight * (2 / 3); if (newHeight && newHeight > 200) { $("#con_div").height(newHeight); } else { $('#viewMoreId').hide() } } $(document).ready(function () { setConDivHeight(); }); $(window).on("load", function () { setConDivHeight(); }); $(window).on("resize", function () { setConDivHeight(); }); var carouselList = ['微信用户 海**唐 用户已获取解答', '微信用户 平**气 用户已获取解答', '微信用户 吃**帅 用户已获取解答', '微信用户 X** 用户已获取解答', '微信用户 汤**迪 用户已获取解答']; // 轮播功能实现 var currentIndex = 0; var carouselInterval; function initCarousel() { var container = $('#carouselContent'); container.empty(); // 生成轮播项,包括首尾各复制一项用于无缝轮播 carouselList.forEach(function (item) { var itemHtml = ''; container.append(itemHtml); }); // 在末尾添加第一项的副本,用于无缝循环 var firstItemHtml = ''; container.append(firstItemHtml); startCarousel(); } function startCarousel() { carouselInterval && clearInterval(carouselInterval); currentIndex = 0; carouselInterval = setInterval(function () { currentIndex++; var offset = -currentIndex * 30; // 每项高度30px $('#carouselContent').css('transform', 'translateY(' + offset + 'px)'); // 当滚动到复制的第一项时,无缝跳回真正的第一项 if (currentIndex === carouselList.length) { setTimeout(function () { $('#carouselContent').css('transition', 'none'); currentIndex = 0; $('#carouselContent').css('transform', 'translateY(0)'); // 恢复过渡效果 setTimeout(function () { $('#carouselContent').css('transition', 'transform 0.5s ease'); }, 50); }, 500); // 等待滚动动画完成 } }, 2200); // 每2秒切换 } // 点击查看更多渐变层显示弹窗 $('.view-more-gradient').on('click', function () { initCarousel(); $('.view-more-pop').css('display', 'flex'); }); // 点击继续阅读隐藏弹窗并移除高度限制 $('.action-read').on('click', function () { carouselInterval && clearInterval(carouselInterval); $('#viewMoreId').hide() $('.view-more-pop').css('display', 'none'); $('#con_div').css('height', 'auto'); }); })();