window.addEventListener('scroll', handleScroll, true) function handleScroll() { if (window.scrollY > 100) { document.getElementsByClassName('handler-app-android-download').item(0).className = "handler-app-android-download" document.getElementsByClassName("handler-to-top").item(0).style.display = "block" } else { document.getElementsByClassName('handler-app-android-download').item(0).className = "handler-app-android-download handler-item-bottom" document.getElementsByClassName("handler-to-top").item(0).style.display = "none" } } function ToTop() { window.scrollTo({ top: 0, behavior: 'smooth' }) } /*//todo 首页轮播图 window.onload = function () { var items = document.getElementsByClassName("item"); var circles = document.getElementsByClassName("circle"); var leftBtn = document.getElementById("btn-left"); var rightBtn = document.getElementById("btn-right"); var content = document.querySelector('.content'); var index = 0; var timer = null; //清除class var clearclass = function () { for (let i = 0; i < items.length; i++) { items[i].className = "item"; circles[i].className = "circle"; circles[i].setAttribute("num", i); } } /!*只显示一个class*!/ function move() { clearclass(); items[index].className = "item active"; circles[index].className = "circle white"; } //点击右边按钮切换下一张图片 rightBtn.onclick = function () { if (index === items.length - 1) { index = 0; } else { index++ } move(); } //点击左边按钮切换上一张图片 leftBtn.onclick = function () { if (index === 0) { index = items.length - 1; } else { index-- } move(); } //开始定时器,点击右边按钮,实现轮播 rightBtn.onclick(); timer = setInterval(function () { rightBtn.onclick(); }, 3000) //点击圆点时,跳转到对应图片 for (var i = 0; i < circles.length; i++) { circles[i].addEventListener("click", function () { var point_index = this.getAttribute("num"); index = point_index; move(); }) } //鼠标移入清除定时器,并开启一个三秒的定时器,使慢慢转动 content.onmouseover = function () { clearInterval(timer); timer = setInterval(function () { rightBtn.onclick(); }, 3000) } //鼠标移出又开启定时器 content.onmouseleave = function () { clearInterval(timer); timer = setInterval(function () { rightBtn.onclick(); }, 1500) } }*/ window.onload = function () { var items = document.getElementsByClassName("item"); var circles = document.getElementsByClassName("circle"); var leftBtn = document.getElementById("btn-left"); var rightBtn = document.getElementById("btn-right"); var content = document.querySelector('.content'); var index = 0; var timer = null; var startX = 0; // 用于记录触摸起始点 var isDragging = false; // 标记是否正在滑动 // 清除class var clearclass = function () { for (let i = 0; i < items.length; i++) { items[i].className = "item"; circles[i].className = "circle"; circles[i].setAttribute("num", i); } } // 显示当前选中的图片和圆点 function move() { clearclass(); items[index].className = "item active"; circles[index].className = "circle white"; } // 点击右边按钮切换下一张图片 rightBtn.onclick = function () { if (index === items.length - 1) { index = 0; } else { index++; } move(); } // 点击左边按钮切换上一张图片 leftBtn.onclick = function () { if (index === 0) { index = items.length - 1; } else { index--; } move(); } //避免打开页面白屏 rightBtn.click() leftBtn.click() // 开始定时器,实现自动轮播 timer = setInterval(function () { rightBtn.onclick(); }, 3000); // 点击圆点时,跳转到对应图片 for (var i = 0; i < circles.length; i++) { circles[i].addEventListener("click", function () { var point_index = this.getAttribute("num"); index = point_index; move(); }); } // 鼠标移入清除定时器 content.onmouseover = function () { clearInterval(timer); } // 鼠标移出重新开始定时器 content.onmouseleave = function () { clearInterval(timer); timer = setInterval(function () { rightBtn.onclick(); }, 3000); } // 触摸事件:触摸开始 content.addEventListener('touchstart', function (e) { startX = e.touches[0].clientX; isDragging = true; clearInterval(timer); // 触摸时暂停自动轮播 }); // 触摸事件:触摸移动 content.addEventListener('touchmove', function (e) { if (!isDragging) return; var currentX = e.touches[0].clientX; var diffX = currentX - startX; if (diffX > 50) { // 向右滑动 leftBtn.onclick(); // 切换到上一张 isDragging = false; } else if (diffX < -50) { // 向左滑动 rightBtn.onclick(); // 切换到下一张 isDragging = false; } }); // 触摸事件:触摸结束 content.addEventListener('touchend', function () { isDragging = false; timer = setInterval(function () { rightBtn.onclick(); }, 3000); // 重新开始自动轮播 }); } var CardListElements = null //初始化加载 topic列表 function TopicListShowLoad() { CardListElements = document.getElementsByClassName("card-list"); for (let i = 0; i < CardListElements.length; i++) { let goodsInfoEles = CardListElements[i].getElementsByClassName("goods-info") for (let i = 0; i < goodsInfoEles.length; i++) { if (goodsInfoEles[i].getAttribute("index") > 12) { goodsInfoEles[i].style.display = "none"; } } let showEle = CardListElements[i].getElementsByClassName("card-show") if (!showEle || showEle.length === 0) { continue } let linkElement = showEle.item(0).getElementsByTagName("a").item(0); linkElement.addEventListener("click", (e) => { if (linkElement.getAttribute("show")==="true") { linkElement.setAttribute("show", "false"); linkElement.innerHTML = "查看更多"; for (let i = 0; i < goodsInfoEles.length; i++) { if (goodsInfoEles[i].getAttribute("index") > 12) { goodsInfoEles[i].style.display = "none"; } } } else { linkElement.setAttribute("show", "true"); linkElement.innerHTML = "收起"; for (let i = 0; i < goodsInfoEles.length; i++) { if (goodsInfoEles[i].getAttribute("index") > 12) { goodsInfoEles[i].style.display = "inline-block"; } } } }) } // let goodsInfoEles = document.getElementsByClassName("goods-info"); // for (let i = 0; i < goodsInfoEles.length; i++) { // if (goodsInfoEles[i].getAttribute("index") > 12) { // goodsInfoEles[i].style.display = "none"; // } // } } handleScroll() TopicListShowLoad()