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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. $(function () {
  2. // $(".header_root").load("./comm/header.html");
  3. $(".footer_root").load("./comm/footer.html");
  4. // nav传值显示下划线
  5. // $(".header_root").data("nav_info", 1);
  6. //获取元素
  7. var divheight = $(".exam_one").height();
  8. var container = $(".exam_container");
  9. var exam_slide = $(".exam_slide"); //右侧图片
  10. var list = $(".show_exam");
  11. var buts = $(".exam_item");
  12. var index = 0; //存放当前显示的图片的下标
  13. var beforeidx = 0; //之前的索引
  14. var interval = 5000; //位移时间间隔
  15. var timer;
  16. var blue = $(".blue");
  17. var grey = $(".grey");
  18. function showimg(index) {
  19. $.each(exam_slide, (idx, item) => {
  20. if (index != idx) {
  21. //隐藏
  22. setTimeout(() => {
  23. exam_slide.eq(idx).css("visibility", "hidden");
  24. }, 500);
  25. } else {
  26. //显示当前索引图片
  27. // exam_slide.eq(idx).css("visibility", "visible");
  28. setTimeout(() => {
  29. exam_slide.eq(idx).css("visibility", "visible");
  30. }, 500);
  31. }
  32. });
  33. }
  34. function animate(offset, type) {
  35. if (!type) {
  36. //自动轮播
  37. showimg(index);
  38. beforeidx = index;
  39. index++;
  40. offset = "-=" + Math.abs(offset);
  41. if (index == 5) {
  42. index = 0;
  43. offset = 0;
  44. }
  45. showButton();
  46. } else {
  47. showimg(beforeidx);
  48. console.log("显示上一张图片");
  49. }
  50. if (index > beforeidx) {
  51. console.log("从下往上滚");
  52. exam_slide
  53. .eq(beforeidx)
  54. .addClass("flip-scale-down-hor")
  55. .siblings("div")
  56. .removeClass("flip-scale-down-hor");
  57. } else {
  58. console.log("从上往下滚");
  59. exam_slide
  60. .eq(beforeidx)
  61. .addClass("flip-scale-up-hor")
  62. .siblings("div")
  63. .removeClass("flip-scale-up-hor");
  64. }
  65. console.log("当前索引", index, "上一个索引", beforeidx);
  66. //
  67. setTimeout(() => {
  68. showimg(index);
  69. exam_slide
  70. .eq(index)
  71. .addClass("flip-scale-up-hor")
  72. .siblings("div")
  73. .removeClass("flip-scale-up-hor");
  74. console.log("显示当前图片");
  75. if (index > beforeidx) {
  76. // exam_slide
  77. // .eq(index)
  78. // .addClass("flip-scale-up-hor")
  79. // .siblings("div")
  80. // .removeClass("flip-scale-up-hor");
  81. } else {
  82. // exam_slide
  83. // .eq(index)
  84. // .addClass("flip-scale-down-hor")
  85. // .siblings("div")
  86. // .removeClass("flip-scale-down-hor");
  87. }
  88. }, 500);
  89. if (type) {
  90. beforeidx = index;
  91. }
  92. }
  93. var imglist = [
  94. {
  95. blue: "../img/product/mtblue.png",
  96. grey: "../img/product/mtgrey.png"
  97. },
  98. {
  99. blue: "../img/product/zdblue.png",
  100. grey: "../img/product/zdgrey.png"
  101. },
  102. {
  103. blue: "../img/product/ydblue.png",
  104. grey: "../img/product/ydgrey.png"
  105. },
  106. {
  107. blue: "../img/product/yyblue.png",
  108. grey: "../img/product/yygrey.png"
  109. },
  110. {
  111. blue: "../img/product/sjblue.png",
  112. grey: "../img/product/sjgrey.png"
  113. }
  114. ];
  115. //亮起小圆点
  116. function showButton() {
  117. buts.each(function (idx, item) {
  118. var curindex = JSON.parse(JSON.stringify(index));
  119. if (idx == index) {
  120. blue.eq(index).show();
  121. } else {
  122. curindex--;
  123. if (curindex == -1) 4;
  124. blue.eq(curindex).hide();
  125. grey.eq(curindex).show();
  126. }
  127. });
  128. }
  129. // 鼠标离开图片区域时,轮播继续
  130. function play() {
  131. timer = setTimeout(function () {
  132. animate(divheight);
  133. play();
  134. }, interval);
  135. }
  136. //鼠标进入图片区域时,停止轮播
  137. function stop() {
  138. if (timer) {
  139. clearTimeout(timer);
  140. timer = null;
  141. }
  142. }
  143. // 点击事件
  144. buts.each(function () {
  145. $(this).bind("click", function () {
  146. var myIndex = parseInt($(this).attr("index"));
  147. if (myIndex == index) {
  148. return;
  149. }
  150. index = myIndex;
  151. showButton();
  152. });
  153. });
  154. //楼梯导航
  155. $(window).on("scroll", function () {
  156. var $scroll = $(this).scrollTop() - 200;
  157. // 拖动滚轮,点亮对应的楼层标签
  158. $(".piece").each(function () {
  159. var $stepTop = $(".piece").eq($(this).index()).offset().top;
  160. // 楼层的top大于滚动条的距离
  161. if ($stepTop > $scroll) {
  162. $(".step").removeClass("active");
  163. $(".step").eq($(this).index()).addClass("active");
  164. // 中断循环
  165. return false;
  166. }
  167. });
  168. });
  169. // 获取每个楼梯的offset().top,点击楼层让对应的内容模块移动到对应的位置
  170. var $stepItem = $(".step");
  171. $stepItem.on("click", function () {
  172. $(this).addClass("active").siblings("div").removeClass("active");
  173. var $stepTop = $(".piece")
  174. .eq($(this).index() - 1)
  175. .offset().top;
  176. // 获取每个楼梯的offsetTop值
  177. $("html,body").animate({
  178. scrollTop: $stepTop
  179. });
  180. });
  181. $.each(blue, function (idx, item) {
  182. if (idx != 0) {
  183. $(this).hide();
  184. }
  185. });
  186. buts.on({
  187. mouseenter: function () {
  188. //移入
  189. var myIndex = parseInt($(this).attr("index"));
  190. if (myIndex == index) {
  191. return;
  192. }
  193. $.each(grey, function (idx, item) {
  194. $(this).show();
  195. });
  196. $.each(blue, function (idx, item) {
  197. if (idx == myIndex) {
  198. $(this).show();
  199. } else {
  200. $(this).hide();
  201. }
  202. });
  203. index = myIndex;
  204. animate(divheight, 1);
  205. },
  206. mouseleave: function () {}
  207. });
  208. // 回到顶部
  209. $(".top").on("click", function () {
  210. $("html,body").animate({
  211. scrollTop: 0
  212. });
  213. });
  214. // container.hover(stop, play);
  215. // play();
  216. // showButton();
  217. });