main.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. function setHtmlFontSize() {
  2. var width = 750 //如果是尺寸的设计稿在这里修改
  3. document.documentElement.style.fontSize = (100 * innerWidth) / width + 'px'
  4. }
  5. setHtmlFontSize()
  6. function windowReload() {
  7. var isMiniScreen = innerWidth <= 768
  8. window.addEventListener('resize', function () {
  9. setHtmlFontSize()
  10. console.log(innerWidth)
  11. if (isMiniScreen) {
  12. if (innerWidth > 768) {
  13. window.location.reload()
  14. }
  15. } else {
  16. if (innerWidth < 768) {
  17. window.location.reload()
  18. }
  19. }
  20. })
  21. }
  22. windowReload()
  23. function startMenuAction() {
  24. $(function () {
  25. var isAnimated = false
  26. $('[data-toggle="dropdown"]').on('click', function () {
  27. if (isAnimated) return
  28. isAnimated = true
  29. $(this).parent('.dropdown').toggleClass('open')
  30. $(this)
  31. .siblings('.dropdown-menu')
  32. .slideToggle(false, function () {
  33. isAnimated = false
  34. })
  35. })
  36. $('[data-toggle="collapse"]').on('click', function () {
  37. if (isAnimated) return
  38. isAnimated = true
  39. var target = $(this).attr('data-target')
  40. var expanded = $(this).attr('aria-expanded')
  41. if (expanded === 'true') {
  42. expanded = 'false'
  43. } else {
  44. expanded = 'true'
  45. }
  46. $(this).attr('aria-expanded', expanded)
  47. $(target).slideToggle(function () {
  48. if (expanded === 'true') {
  49. $(this).css('background', 'rgba(0, 0, 0, 0.3)')
  50. } else {
  51. $(this).css('background', 'transparent')
  52. }
  53. isAnimated = false
  54. })
  55. })
  56. })
  57. }
  58. startMenuAction()