星火官网,前端页面(前台)
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

product.js 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. $(function () {
  2. $(".header_root").load("./comm/header.html");
  3. $(".footer_root").load("./comm/footer.html");
  4. //获取元素
  5. var divheight = $(".exam_one").height();
  6. var container = $(".exam_container");
  7. var list = $(".show_exam");
  8. var buts = $(".exam_item");
  9. var index = 0; //存放当前显示的图片的下标
  10. var interval = 5000; //位移时间间隔
  11. var timer;
  12. function animate(offset) {
  13. var top = parseInt(list.css("top")) + offset;
  14. console.log(list.css("top"));
  15. var absnum = Math.abs(offset);
  16. index++;
  17. // 边界判断
  18. // if (offset > 0) {
  19. // offset = "+=" + offset;
  20. // } else {
  21. // offset = "-=" + Math.abs(offset);
  22. // }
  23. offset = "-=" + Math.abs(offset);
  24. if (index == 5) {
  25. index = 0;
  26. offset = 0;
  27. }
  28. showButton();
  29. console.log("当前索引", index, top, offset);
  30. list.animate({ top: offset }, 300, function () {
  31. if (top > -200) {
  32. }
  33. });
  34. }
  35. var imglist = [
  36. {
  37. blue: "../img/product/mtblue.png",
  38. grey: "../img/product/mtgrey.png"
  39. },
  40. {
  41. blue: "../img/product/zdblue.png",
  42. grey: "../img/product/zdgrey.png"
  43. },
  44. {
  45. blue: "../img/product/ydblue.png",
  46. grey: "../img/product/ydgrey.png"
  47. },
  48. {
  49. blue: "../img/product/yyblue.png",
  50. grey: "../img/product/yygrey.png"
  51. },
  52. {
  53. blue: "../img/product/sjblue.png",
  54. grey: "../img/product/sjgrey.png"
  55. }
  56. ];
  57. //亮起小圆点
  58. function showButton() {
  59. var html = "";
  60. buts.each(function (idx, item) {
  61. if (idx == index) {
  62. $(this).html(`<img src="${imglist[idx].blue}" />`);
  63. } else {
  64. $(this).html(`<img src="${imglist[idx].grey}" />`);
  65. }
  66. });
  67. }
  68. // 鼠标离开图片区域时,轮播继续
  69. function play() {
  70. timer = setTimeout(function () {
  71. animate(divheight);
  72. play();
  73. }, interval);
  74. }
  75. //鼠标进入图片区域时,停止轮播
  76. function stop() {
  77. if (timer) {
  78. clearTimeout(timer);
  79. timer = null;
  80. }
  81. }
  82. // 点击事件
  83. buts.each(function () {
  84. $(this).bind("click", function () {
  85. var myIndex = parseInt($(this).attr("index"));
  86. if (myIndex == index) {
  87. return;
  88. }
  89. index = myIndex;
  90. showButton();
  91. });
  92. });
  93. container.hover(stop, play);
  94. play();
  95. showButton();
  96. });