星火官网,前端页面(前台)
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

about.js 5.6KB

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