星火官网,前端页面(前台)
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 5.4KB

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