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

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