main.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. if (expanded === 'false') {
  48. $(target).css('background-color', 'transparent')
  49. }
  50. $(target).slideToggle(function () {
  51. if (expanded === 'true') {
  52. $(this).css('background-color', 'rgba(0, 0, 0, 0.6)')
  53. }
  54. isAnimated = false
  55. })
  56. })
  57. })
  58. }
  59. startMenuAction()