index.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. window.addEventListener('scroll', handleScroll, true)
  2. function handleScroll() {
  3. if (window.scrollY > 100) {
  4. document.getElementsByClassName('handler-app-android-download').item(0).className = "handler-app-android-download"
  5. document.getElementsByClassName("handler-to-top").item(0).style.display = "block"
  6. } else {
  7. document.getElementsByClassName('handler-app-android-download').item(0).className = "handler-app-android-download handler-item-bottom"
  8. document.getElementsByClassName("handler-to-top").item(0).style.display = "none"
  9. }
  10. }
  11. function ToTop() {
  12. window.scrollTo({
  13. top: 0,
  14. behavior: 'smooth'
  15. })
  16. }
  17. //todo 首页轮播图
  18. window.onload = function () {
  19. var items = document.getElementsByClassName("item");
  20. var circles = document.getElementsByClassName("circle");
  21. var leftBtn = document.getElementById("btn-left");
  22. var rightBtn = document.getElementById("btn-right");
  23. var content = document.querySelector('.content');
  24. var index = 0;
  25. var timer = null;
  26. //清除class
  27. var clearclass = function () {
  28. for (let i = 0; i < items.length; i++) {
  29. items[i].className = "item";
  30. circles[i].className = "circle";
  31. circles[i].setAttribute("num", i);
  32. }
  33. }
  34. /*只显示一个class*/
  35. function move() {
  36. clearclass();
  37. items[index].className = "item active";
  38. circles[index].className = "circle white";
  39. }
  40. //点击右边按钮切换下一张图片
  41. rightBtn.onclick = function () {
  42. if (index === items.length - 1) {
  43. index = 0;
  44. } else {
  45. index++
  46. }
  47. move();
  48. }
  49. //点击左边按钮切换上一张图片
  50. leftBtn.onclick = function () {
  51. if (index === 0) {
  52. index = items.length - 1;
  53. } else {
  54. index--
  55. }
  56. move();
  57. }
  58. //开始定时器,点击右边按钮,实现轮播
  59. rightBtn.onclick();
  60. timer = setInterval(function () {
  61. rightBtn.onclick();
  62. }, 3000)
  63. //点击圆点时,跳转到对应图片
  64. for (var i = 0; i < circles.length; i++) {
  65. circles[i].addEventListener("click", function () {
  66. var point_index = this.getAttribute("num");
  67. index = point_index;
  68. move();
  69. })
  70. }
  71. //鼠标移入清除定时器,并开启一个三秒的定时器,使慢慢转动
  72. content.onmouseover = function () {
  73. clearInterval(timer);
  74. timer = setInterval(function () {
  75. rightBtn.onclick();
  76. }, 3000)
  77. }
  78. //鼠标移出又开启定时器
  79. content.onmouseleave = function () {
  80. clearInterval(timer);
  81. timer = setInterval(function () {
  82. rightBtn.onclick();
  83. }, 1500)
  84. }
  85. }
  86. var CardListElements = null
  87. //初始化加载 topic列表
  88. function TopicListShowLoad() {
  89. CardListElements = document.getElementsByClassName("card-list");
  90. for (let i = 0; i < CardListElements.length; i++) {
  91. let goodsInfoEles = CardListElements[i].getElementsByClassName("goods-info")
  92. for (let i = 0; i < goodsInfoEles.length; i++) {
  93. if (goodsInfoEles[i].getAttribute("index") > 12) {
  94. goodsInfoEles[i].style.display = "none";
  95. }
  96. }
  97. let showEle = CardListElements[i].getElementsByClassName("card-show")
  98. if (!showEle || showEle.length === 0) {
  99. continue
  100. }
  101. let linkElement = showEle.item(0).getElementsByTagName("a").item(0);
  102. linkElement.addEventListener("click", (e) => {
  103. if (linkElement.getAttribute("show")==="true") {
  104. linkElement.setAttribute("show", "false");
  105. linkElement.innerHTML = "查看更多";
  106. for (let i = 0; i < goodsInfoEles.length; i++) {
  107. if (goodsInfoEles[i].getAttribute("index") > 12) {
  108. goodsInfoEles[i].style.display = "none";
  109. }
  110. }
  111. } else {
  112. linkElement.setAttribute("show", "true");
  113. linkElement.innerHTML = "收起";
  114. for (let i = 0; i < goodsInfoEles.length; i++) {
  115. if (goodsInfoEles[i].getAttribute("index") > 12) {
  116. goodsInfoEles[i].style.display = "inline-block";
  117. }
  118. }
  119. }
  120. })
  121. }
  122. // let goodsInfoEles = document.getElementsByClassName("goods-info");
  123. // for (let i = 0; i < goodsInfoEles.length; i++) {
  124. // if (goodsInfoEles[i].getAttribute("index") > 12) {
  125. // goodsInfoEles[i].style.display = "none";
  126. // }
  127. // }
  128. }
  129. // fetch('/api/order/submit', {
  130. // method: 'POST',
  131. // headers: {
  132. // 'Content-Type': 'application/json'
  133. // },
  134. // body: JSON.stringify(data)
  135. // })
  136. // .then(response => response.json())
  137. // .then(data => {
  138. // console.log('Success:', data);
  139. // alert("假装购买成功");
  140. // })
  141. // .catch((error) => {
  142. // console.error('Error:', error);
  143. // alert("购买失败");
  144. // });
  145. handleScroll()
  146. TopicListShowLoad()