perf.html 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. }
  12. .container {
  13. width: 20%;
  14. background: #FF9800;
  15. cursor: pointer;
  16. position: relative;
  17. border-right: 1px solid black;
  18. border-left: 1px solid black;
  19. }
  20. .container.elq-width-under-200 {
  21. height: 200px;
  22. }
  23. .container.elq-width-above-200 {
  24. height: 400px;
  25. }
  26. #dimensions {
  27. font-size: 3em;
  28. color: #FFF;
  29. }
  30. #dim-x, #dim-y {
  31. color: #263248;
  32. }
  33. </style>
  34. </head>
  35. <body>
  36. <button onclick="resize()">Resize</button>
  37. <div id="aligner">
  38. </div>
  39. <script src="../node_modules/jquery/dist/jquery.min.js"></script>
  40. <script src="../build/element-resize-detector.js"></script>
  41. <script>
  42. var alignerWidth = 100;
  43. var cnt = 0;
  44. function resize() {
  45. if(alignerWidth === 100) {
  46. alignerWidth = 50;
  47. } else {
  48. alignerWidth = 100;
  49. }
  50. $("#aligner").width(alignerWidth + "%");
  51. console.time("resize");
  52. }
  53. $(function() {
  54. function onElementResize(element) {
  55. if(++cnt === numElements) {
  56. cnt = 0;
  57. console.timeEnd("resize");
  58. }
  59. }
  60. function createDiv(width) {
  61. var d = document.createElement("div");
  62. d.className = "container";
  63. d.style.width = width;
  64. return d;
  65. }
  66. function loopCreateAndAppend(numNested, create, target) {
  67. for(var i = 0; i < numNested; i++) {
  68. var d = create();
  69. target.appendChild(d);
  70. }
  71. return target;
  72. }
  73. var numElements = 200;
  74. loopCreateAndAppend(numElements, createDiv.bind(null, numElements), document.getElementById("aligner"));
  75. (function listenToResize() {
  76. var erd = elementResizeDetectorMaker({
  77. strategy: "scroll"
  78. });
  79. console.time("install");
  80. erd.listenTo({
  81. callOnAdd: false,
  82. onReady: function onReady() {
  83. console.timeEnd("install");
  84. console.log("ready");
  85. }
  86. }, $(".container"), onElementResize);
  87. })();
  88. });
  89. </script>
  90. </body>
  91. </html>