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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. var datalist = [
  2. { time: 2023 },
  3. { time: 2022 },
  4. { time: 2021 },
  5. { time: 2020 },
  6. { time: 2019 },
  7. { time: 2018 }
  8. ];
  9. var html = "";
  10. $.each(datalist, (idx, item) => {
  11. html += `<div class="round_q">
  12. <div class="round_item">
  13. <div class="round_i"></div>
  14. <div class="round_d">${item.time}</div>
  15. </div></div>`;
  16. });
  17. $(".rounds").width(datalist.length * 2.34 + "rem");
  18. $(".rounds").html(html);
  19. $(".round_q:first").addClass("active"); //默认第一个添加背景色
  20. //获取元素
  21. var divwidth = $(".round_q:first").width() - 54;
  22. console.log(divwidth);
  23. var container = $(".showdata");
  24. var list = $(".rounds");
  25. var buts = $(".round_q");
  26. var prev = $(".leftjt");
  27. var next = $(".rightjt");
  28. var index = 1; //存放当前显示的图片的下标
  29. var len = 5;
  30. var interval = 5000; //位移时间间隔
  31. var timer;
  32. function animate(offset) {
  33. console.log(index);
  34. var left = parseInt(list.css("left")) + offset;
  35. console.log(left, offset);
  36. // 边界判断
  37. if (offset > 0) {
  38. offset = "+=" + offset;
  39. } else {
  40. offset = "-=" + Math.abs(offset);
  41. }
  42. list.animate({ left: offset }, 300, function () {
  43. if (left > -200) {
  44. console.log(22);
  45. list.css("left", (0 - offset) * len);
  46. }
  47. console.log(offset * len);
  48. if (left < offset * len) {
  49. console.log(111);
  50. list.css("left", 0 - offset);
  51. }
  52. });
  53. }
  54. //亮起小圆点
  55. function showButton() {
  56. //当前图片的小圆点亮起,其他小圆点不亮
  57. console.log("gaoliang");
  58. buts
  59. .eq(index - 1)
  60. .addClass("active")
  61. .siblings()
  62. .removeClass("active");
  63. }
  64. // 鼠标离开图片区域时,轮播继续
  65. function play() {
  66. timer = setTimeout(function () {
  67. next.trigger("click");
  68. play();
  69. }, interval);
  70. }
  71. //鼠标进入图片区域时,停止轮播
  72. function stop() {
  73. clearTimeout(timer);
  74. }
  75. // 右按钮点击事件
  76. next.bind("click", function () {
  77. // 判断当前是否在动画
  78. if (list.is(":animated")) {
  79. return;
  80. }
  81. // 判断当前图片是否是最后一张
  82. if (index == 5) {
  83. index = 1;
  84. } else {
  85. index += 1;
  86. }
  87. console.log("you", index);
  88. animate(0 - divwidth);
  89. showButton();
  90. });
  91. // 左按钮事件
  92. prev.bind("click", function () {
  93. // 判断当前是否在动画
  94. if (list.is(":animated")) {
  95. return;
  96. }
  97. // 判断当前图片是否是第一张
  98. if (index == 1) {
  99. index = 5;
  100. } else {
  101. index -= 1;
  102. }
  103. console.log(zuo, index);
  104. animate(divwidth);
  105. showButton();
  106. });
  107. // 小圆点点击事件
  108. // buttons.each(function () {
  109. // $(this).bind("click", function () {
  110. // // 判断当前是否在进行动画
  111. // if (list.is(":animated") || $(this).attr("class") == "on") {
  112. // return;
  113. // }
  114. // // 获取属性
  115. // var myIndex = parseInt($(this).attr("index"));
  116. // //计算偏移量
  117. // var offset = -600 * (myIndex - index);
  118. // animate(offset);
  119. // //切换后,更新当前的偏移量
  120. // index = myIndex;
  121. // showButton();
  122. // });
  123. // });
  124. container.hover(stop, play);
  125. play();