main.dev.js 1.6 KB

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