detail.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. "use strict";
  2. function initPreviewImage() {
  3. var imageGroup = {};
  4. var imageEls = document.querySelectorAll('.content');
  5. if (imageEls.length <= 0) return;
  6. imageEls.forEach(function (imageEl, index) {
  7. imageGroup['cm-images-' + index] = new Viewer(imageEl);
  8. });
  9. console.log('初始化图片预览成功')
  10. }
  11. $(function () {
  12. // 页面滚动偏移
  13. var offset = 0;
  14. var windowWidth = $(window).width();
  15. var timer = null; // 定时器
  16. var middleScreenWidth = 1450;
  17. // 生成导航
  18. makeNavigate('.section .title h2', '.navigate');
  19. if (windowWidth > 768) {
  20. offset = getScrollOffset('.navbar') + 10;
  21. } else {
  22. offset = getScrollOffset(['.navbar', '.navigate']) + 10;
  23. }
  24. // 侧边导航跳转
  25. bindCategory('.navigate li', '.section', offset, function (index) {
  26. activeCategory('.navigate li', index);
  27. });
  28. // 页面滚动观测
  29. pageScrollObserve('.section', offset, function (el, index) {
  30. if (index > -1) {
  31. activeCategory('.navigate li', index);
  32. }
  33. });
  34. // 常见问题展开收起
  35. $('[data-toggle="collapse"]').each(function (index, el) {
  36. var targetEl = $(el).attr('data-target');
  37. if (!targetEl) return;
  38. $(targetEl).hide();
  39. $(el).on('click', function () {
  40. $(targetEl).toggle();
  41. $(el).toggleClass('arrowup');
  42. });
  43. });
  44. $('#contactPopupBtn').on('click', function () {
  45. $('#contactPopup').show();
  46. });
  47. $('#contactPopupClose').on('click', function () {
  48. $('#contactPopup').hide();
  49. });
  50. // 切换显示侧边导航
  51. function toggleNavigate(selector, time, maxWidth, offset) {
  52. selector = $(selector);
  53. if (windowWidth <= middleScreenWidth) {
  54. selector.hide();
  55. }
  56. // 鼠标移动事件
  57. $('body').on('mousemove', function (e) {
  58. var width = $(this).width();
  59. if (!(e.clientX > width - offset && width <= maxWidth)) return;
  60. clearTimeout(timer);
  61. selector.fadeIn();
  62. timer = setTimeout(function () {
  63. selector.fadeOut();
  64. }, time)
  65. });
  66. // 窗口大小改变
  67. $(window).resize(function () {
  68. if ($(this).width() <= maxWidth) {
  69. selector.hide();
  70. } else {
  71. selector.show();
  72. }
  73. });
  74. }
  75. initPreviewImage()
  76. // toggleNavigate('.navigate', 1000, middleScreenWidth, 80);
  77. });