index.html 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  7. <title>Resize Detector</title>
  8. <style>
  9. *,
  10. *::before,
  11. *::after {
  12. box-sizing: border-box;
  13. }
  14. html {
  15. font-size: 12px;
  16. color: #999;
  17. }
  18. #container {
  19. width: 600px;
  20. }
  21. #pusher {
  22. float: left;
  23. width: 100px;
  24. height: 100px;
  25. line-height: 100px;
  26. text-align: center;
  27. background: #eee;
  28. cursor: pointer;
  29. transition: width 2s, background-color .3s;
  30. }
  31. #pusher:hover {
  32. width: 300px;
  33. }
  34. :checked + #pusher {
  35. width: 400px;
  36. background: #eec;
  37. }
  38. #el {
  39. position: relative;
  40. overflow: hidden;
  41. height: 100px;
  42. background: #9ca;
  43. line-height: 100px;
  44. text-align: center;
  45. color: #fff;
  46. font-weight: 700;
  47. }
  48. #wrapper {
  49. width: 300px;
  50. height: 200px;
  51. transition: width .5s;
  52. }
  53. #wrapper.expanded {
  54. width: 450px;
  55. }
  56. #r1,
  57. #r2 {
  58. width: 100%;
  59. height: 100px;
  60. }
  61. #r1 {
  62. background: #acc;
  63. }
  64. #r2 {
  65. background: #cca;
  66. }
  67. #output {
  68. white-space: pre-wrap;
  69. }
  70. .log {
  71. display: inline-block;
  72. padding: 2px 5px;
  73. margin: 0 1px 1px 0;
  74. background-color: #cce;
  75. }
  76. </style>
  77. </head>
  78. <body>
  79. <p><label id="attach"><input type="checkbox" checked> Attached</button></label></p>
  80. <p><label id="display"><input type="checkbox"><code>display: none</code></label></p>
  81. <div id="container">
  82. <input id="push" type="checkbox" style="display: none">
  83. <label id="pusher" for="push">Hover or Click</label>
  84. <div id="el">&rarr; Resize Detector Enabled &larr;</div>
  85. </div>
  86. <section id="wrapper">
  87. <div id="r1"></div>
  88. <div id="r2"></div>
  89. </section>
  90. <pre id="output"></pre>
  91. <script src="../dist/index.js"></script>
  92. <script>
  93. var el = document.getElementById('el')
  94. var container = document.getElementById('container')
  95. var attach = document.getElementById('attach')
  96. var wrapper = document.getElementById('wrapper')
  97. var r1 = document.getElementById('r1')
  98. var r2 = document.getElementById('r2')
  99. var display = document.getElementById('display')
  100. var output = document.getElementById('output')
  101. function log (msg) {
  102. output.innerHTML += `<span class="log">${msg}</span>`
  103. }
  104. resizeDetector.addListener(el, function () {
  105. log(el.offsetWidth + '×' + el.offsetHeight)
  106. })
  107. attach.addEventListener('change', function () {
  108. var input = attach.firstElementChild
  109. if (input.checked) {
  110. container.appendChild(el)
  111. } else {
  112. container.removeChild(el)
  113. }
  114. })
  115. display.addEventListener('change', function () {
  116. var input = display.firstElementChild
  117. if (input.checked) {
  118. el.style.display = 'none'
  119. } else {
  120. el.style.display = ''
  121. }
  122. })
  123. wrapper.addEventListener('click', function () {
  124. wrapper.classList.toggle('expanded')
  125. })
  126. resizeDetector.addListener(r1, function () {
  127. log('r1: resize')
  128. })
  129. resizeDetector.addListener(r2, function () {
  130. log('r2: resize')
  131. })
  132. </script>
  133. </body>
  134. </html>