index.js 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. const items = document.querySelectorAll('.problem_box_item');
  2. items.forEach(item => {
  3. item.addEventListener('click', () => {
  4. // 移除其他项的样式
  5. // items.forEach(i => i.classList.remove('problem_box_item_sele'));
  6. // 添加当前点击项的样式
  7. if(item.classList.contains('problem_box_item_sele')) {
  8. item.classList.remove('problem_box_item_sele')
  9. } else {
  10. item.classList.add('problem_box_item_sele');
  11. }
  12. });
  13. });
  14. const menuBtn = document.querySelector('.head_tab_menu');
  15. const maskBox = document.querySelector('.mask-box');
  16. const menuBox = document.querySelector('.menu-box');
  17. menuBtn.addEventListener('click', () => {
  18. document.body.style.overflow='hidden';
  19. maskBox.classList.add('mask-box-show');
  20. menuBox.classList.add('menu-box-show')
  21. });
  22. maskBox.addEventListener('click', () => {
  23. document.body.style.overflow='visible';
  24. maskBox.classList.remove('mask-box-show')
  25. menuBox.classList.remove('menu-box-show')
  26. });
  27. menuBox.addEventListener('click', (event) => {
  28. event.stopPropagation(); // 停止事件冒泡
  29. });
  30. // 滚动关于我们
  31. const toAbout = document.querySelectorAll('.toAbout');
  32. toAbout.forEach(item => {
  33. item.addEventListener('click', () => {
  34. document.getElementById('aboutClass').scrollIntoView({behavior: 'smooth'})
  35. })
  36. });
  37. // 滚动合作伙伴
  38. const toCooperation = document.querySelectorAll('.toCooperation');
  39. toCooperation.forEach(item => {
  40. item.addEventListener('click', () => {
  41. document.getElementById('cooperationClass').scrollIntoView({behavior: 'smooth'})
  42. })
  43. });
  44. // 滚动联系我们
  45. const contactBtn = document.querySelectorAll('.toContactMy');
  46. contactBtn.forEach(item => {
  47. item.addEventListener('click', () => {
  48. document.getElementById('contactMy').scrollIntoView({behavior: 'smooth'})
  49. })
  50. });
  51. // 滚动顶部
  52. const toHeadBox = document.querySelectorAll('.toHeadBox');
  53. toHeadBox.forEach(item => {
  54. item.addEventListener('click', () => {
  55. document.getElementById('headBox').scrollIntoView({behavior: 'smooth'})
  56. })
  57. });
  58. // 充电桩滚动切换
  59. const userItem = document.querySelectorAll('.user_box_item');
  60. let userItemNumber = (Number((userItem.length / 2).toFixed(0)) - 1)
  61. let userScrollIndex = 0
  62. const userLeftBtn = document.querySelector('.scroll_btn_left');
  63. const userRightBtn = document.querySelector('.scroll_btn_right');
  64. const userScroll = document.querySelector('.user_box_scroll_center');
  65. userLeftBtn.addEventListener('click', () => {
  66. if(userScrollIndex != 0) {
  67. userScrollIndex--
  68. let ere = (50 * userScrollIndex) + '% - ' + (0.625 * userScrollIndex) + 'rem'
  69. userScroll.style.cssText = 'transform: translate(calc(-'+ ere + '), 0);'
  70. }
  71. });
  72. userRightBtn.addEventListener('click', () => {
  73. if(userScrollIndex < userItemNumber) {
  74. userScrollIndex++
  75. let ere = (50 * userScrollIndex) + '% - ' + (0.625 * userScrollIndex) + 'rem'
  76. userScroll.style.cssText = 'transform: translate(calc(-'+ ere + '), 0);'
  77. }
  78. });