星火官网,前端页面(前台)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

about.js 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. // 请求接口前缀
  2. var Baseurl = "https://xhwebapitest.xhkjedu.com/dh/list";
  3. // $.ajax({
  4. // type: "POST",
  5. // url: Baseurl,
  6. // data: JSON.stringify({
  7. // examid: 434,
  8. // classid: 9666
  9. // }),
  10. // dataType: "json",
  11. // contentType: "application/json; charset=utf-8",
  12. // success: function (data) {
  13. // if (data.code === 0) {
  14. // loadSectionHtml(data.obj);
  15. // } else {
  16. // alert(data.msg);
  17. // }
  18. // }
  19. // });
  20. var datalist = [
  21. { time: 2023 },
  22. { time: 2022 },
  23. { time: 2021 },
  24. { time: 2020 },
  25. { time: 2019 },
  26. { time: 2018 },
  27. { time: 2017 }
  28. ];
  29. var html = "";
  30. $.each(datalist, (idx, item) => {
  31. html += `<div class="round_q" index = "${idx + 1}">
  32. <div class="round_item">
  33. <div class="round_i"></div>
  34. <div class="round_d">${item.time}</div>
  35. </div></div>`;
  36. });
  37. $(".rounds").width(datalist.length * 2.34 + "rem");
  38. $(".rounds").html(html);
  39. $(".round_q:first").addClass("active"); //默认第一个添加背景色
  40. //获取元素
  41. var divwidth = $(".round_q:first").width() - 54;
  42. console.log(divwidth);
  43. var container = $(".showdata");
  44. var list = $(".rounds");
  45. var buts = $(".round_q");
  46. var prev = $(".leftjt");
  47. var next = $(".rightjt");
  48. var index = 1; //存放当前显示的图片的下标
  49. var len = 5; //显示数量
  50. var interval = 5000; //位移时间间隔
  51. var timer;
  52. var offsetpx = (datalist.length - len) * divwidth; //可偏移度
  53. var offleft = 0; //当前偏移量
  54. console.log(offsetpx);
  55. function animate(offset) {
  56. console.log(index);
  57. var left = parseInt(list.css("left")) + offset;
  58. console.log(left, offset);
  59. var absnum = Math.abs(offset);
  60. if (left < 0 - offsetpx) {
  61. //右侧没有数据时不偏移
  62. return;
  63. }
  64. // 边界判断
  65. if (offset > 0) {
  66. offset = "+=" + offset;
  67. offleft = offleft + absnum;
  68. console.log(offset);
  69. } else {
  70. offset = "-=" + Math.abs(offset);
  71. offleft = offleft - absnum;
  72. console.log(0 - absnum, absnum);
  73. }
  74. // if (index == datalist.length) {
  75. // offset = 0 - (datalist.length - 5) * absnum;
  76. // offleft = offset;
  77. // console.log(offset);
  78. // }
  79. console.log(offset, offleft, "当前偏移量");
  80. if (offset >= 0) {
  81. console.log(44444);
  82. return;
  83. }
  84. list.animate({ left: offset }, 300, function () {
  85. if (left > -200) {
  86. console.log(22, (0 - offset) * len);
  87. list.css("left", (0 - offset) * len);
  88. }
  89. if (index == datalist.length) {
  90. offset = 0 - (datalist.length - 5) * absnum;
  91. offleft = offset;
  92. list.css("left", offset);
  93. console.log(offset, 1231312);
  94. }
  95. });
  96. }
  97. //亮起小圆点
  98. function showButton() {
  99. //当前图片的小圆点亮起,其他小圆点不亮
  100. console.log(index, "gaoliang");
  101. buts
  102. .eq(index - 1)
  103. .addClass("active")
  104. .siblings()
  105. .removeClass("active");
  106. }
  107. $(".develop_container").bind("mouseenter", () => {
  108. stop();
  109. });
  110. $(".develop_container").bind("mouseleave", () => {
  111. play();
  112. });
  113. // 鼠标离开图片区域时,轮播继续
  114. function play() {
  115. timer = setTimeout(function () {
  116. next.trigger("click");
  117. play();
  118. }, interval);
  119. }
  120. //鼠标进入图片区域时,停止轮播
  121. function stop() {
  122. clearTimeout(timer);
  123. }
  124. // 右按钮点击事件
  125. next.bind("click", function () {
  126. // 判断当前是否在动画
  127. if (list.is(":animated")) {
  128. return;
  129. }
  130. // 判断当前图片是否是最后一张
  131. if (index == datalist.length) {
  132. index = 1;
  133. console.log(222222);
  134. offleft = 0;
  135. list.animate({ left: 0 }, 300, () => {});
  136. } else {
  137. index += 1;
  138. }
  139. console.log(offleft, "当前偏移量");
  140. console.log("you", index);
  141. animate(0 - divwidth);
  142. showButton();
  143. stop();
  144. });
  145. // 左按钮事件
  146. prev.bind("click", function () {
  147. // 判断当前是否在动画
  148. if (list.is(":animated")) {
  149. return;
  150. }
  151. console.log(index);
  152. // 判断当前图片是否是第一张
  153. if (index == 1) {
  154. index = datalist.length;
  155. } else {
  156. index -= 1;
  157. }
  158. console.log("zuo", index);
  159. console.log(offleft, "当前偏移量");
  160. animate(divwidth);
  161. showButton();
  162. stop();
  163. });
  164. // 小圆点点击事件
  165. buts.each(function () {
  166. $(this).bind("click", function () {
  167. // 判断当前是否在进行动画
  168. if (list.is(":animated") || $(this).attr("class") == "on") {
  169. return;
  170. }
  171. // 获取属性
  172. var myIndex = parseInt($(this).attr("index"));
  173. console.log(myIndex);
  174. //计算偏移量
  175. var offset = (0 - divwidth) * (myIndex - index);
  176. if (myIndex <= 2) {
  177. offset = 0;
  178. console.log(myIndex, 33333);
  179. }
  180. console.log(offleft, "当前偏移量");
  181. animate(offset);
  182. //切换后,更新当前的偏移量
  183. index = myIndex;
  184. showButton();
  185. });
  186. });
  187. container.hover(stop, play);
  188. play();