index.html 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <style>
  5. html, body {
  6. height: 100%;
  7. }
  8. #aligner {
  9. height: 100%;
  10. display: flex;
  11. align-items: center;
  12. justify-content: center;
  13. }
  14. #container {
  15. width: 50%;
  16. height: 50%;
  17. background: #FF9800;
  18. display: flex;
  19. align-items: center;
  20. justify-content: center;
  21. cursor: pointer;
  22. position: relative;
  23. }
  24. #dimensions {
  25. font-size: 3em;
  26. color: #FFF;
  27. }
  28. #dim-x, #dim-y {
  29. color: #263248;
  30. }
  31. </style>
  32. </head>
  33. <body>
  34. <div id="aligner">
  35. <div id="container">
  36. <div id="dimensions">
  37. <span id="dim-x"></span>x<span id="dim-y"></span>
  38. </div>
  39. </div>
  40. </div>
  41. <script src="../node_modules/jquery/dist/jquery.min.js"></script>
  42. <script src="../build/element-resize-detector.js"></script>
  43. <script>
  44. $(function onDomReady() {
  45. function updateDimensions(element) {
  46. var style = getComputedStyle(element);
  47. var width = parseInt(style.width);
  48. var height = parseInt(style.height);
  49. $("#dim-x").html(width);
  50. $("#dim-y").html(height);
  51. }
  52. var container = $("#container");
  53. var erd = elementResizeDetectorMaker({
  54. strategy: "scroll",
  55. callOnAdd: true,
  56. debug: true
  57. });
  58. erd.listenTo(container, updateDimensions);
  59. container.click(function onContainerClick() {
  60. function rand(min, max) {
  61. return Math.floor(Math.random() * (max - min + 1)) + min;
  62. }
  63. var width = rand(30, 90);
  64. var height = rand(30, 90);
  65. $(this).css({
  66. width: width + "%",
  67. height: height + "%"
  68. });
  69. });
  70. });
  71. </script>
  72. </body>
  73. </html>