|
|
@@ -17,7 +17,7 @@ function ToTop() {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
-//todo 首页轮播图
|
|
|
+/*//todo 首页轮播图
|
|
|
window.onload = function () {
|
|
|
var items = document.getElementsByClassName("item");
|
|
|
var circles = document.getElementsByClassName("circle");
|
|
|
@@ -36,7 +36,7 @@ window.onload = function () {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /*只显示一个class*/
|
|
|
+ /!*只显示一个class*!/
|
|
|
function move() {
|
|
|
clearclass();
|
|
|
items[index].className = "item active";
|
|
|
@@ -89,6 +89,113 @@ window.onload = 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
|
|
|
@@ -139,29 +246,6 @@ function TopicListShowLoad() {
|
|
|
|
|
|
}
|
|
|
|
|
|
-// fetch('/api/order/submit', {
|
|
|
-// method: 'POST',
|
|
|
-// headers: {
|
|
|
-// 'Content-Type': 'application/json'
|
|
|
-// },
|
|
|
-// body: JSON.stringify(data)
|
|
|
-// })
|
|
|
-// .then(response => response.json())
|
|
|
-// .then(data => {
|
|
|
-// console.log('Success:', data);
|
|
|
-// alert("假装购买成功");
|
|
|
-// })
|
|
|
-// .catch((error) => {
|
|
|
-// console.error('Error:', error);
|
|
|
-// alert("购买失败");
|
|
|
-// });
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
|
|
|
|
|
|
|