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

product.js 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. //获取元素
  2. var divheight = $(".exam_one").height()-70;
  3. var container = $(".exam_container");
  4. var list = $(".show_exam");
  5. var buts = $(".exam_item");
  6. var index = 1; //存放当前显示的图片的下标
  7. var imgnum = 3; // 图片数量
  8. var len = 1; //显示数量
  9. var interval = 5000; //位移时间间隔
  10. var timer;
  11. function animate(offset) {
  12. var top = parseInt(list.css("top")) + offset;
  13. console.log(list.css("top"));
  14. var absnum = Math.abs(offset);
  15. index++
  16. // 边界判断
  17. // if (offset > 0) {
  18. // offset = "+=" + offset;
  19. // } else {
  20. // offset = "-=" + Math.abs(offset);
  21. // }
  22. offset = "-=" + Math.abs(offset);
  23. if(index == 6){
  24. index = 1;
  25. offset=0;
  26. console.log("最后一个");
  27. }
  28. console.log("当前索引",index, top, offset)
  29. list.animate({ top: offset }, 300, function () {
  30. if (top > -200) {
  31. }
  32. });
  33. }
  34. //亮起小圆点
  35. function showButton() {
  36. console.log("亮起小圆点", index);
  37. //当前图片的小圆点亮起,其他小圆点不亮
  38. buts
  39. .eq(index - 1)
  40. .addClass("active")
  41. .siblings()
  42. .removeClass("active");
  43. }
  44. console.log(divheight);
  45. // 鼠标离开图片区域时,轮播继续
  46. function play() {
  47. console.log("鼠标离开");
  48. timer = setTimeout(function () {
  49. animate(divheight);
  50. play();
  51. }, interval);
  52. }
  53. //鼠标进入图片区域时,停止轮播
  54. function stop() {
  55. console.log("鼠标进入");
  56. if (timer) {
  57. clearTimeout(timer);
  58. timer = null;
  59. }
  60. }
  61. // 点击事件
  62. buts.each(function () {
  63. $(this).bind("click", function () {
  64. // 判断当前是否在进行动画
  65. if (list.is(":animated") || $(this).attr("class") == "on") {
  66. return;
  67. }
  68. var myIndex = parseInt($(this).attr("index"));
  69. if (myIndex == index) {
  70. return;
  71. }
  72. //计算偏移量
  73. var offset = (0 - divwidth) * (myIndex - index);
  74. index = myIndex;
  75. animates(offset);
  76. showButton();
  77. stop();
  78. });
  79. });
  80. container.hover(stop, play);
  81. play();