1 changed files with 16 additions and 6 deletions
@ -1,16 +1,26 @@ |
|||||
'use strict'; |
'use strict'; |
||||
|
|
||||
|
let height = getCurrentHeight(); |
||||
setupResizeListener(); |
setupResizeListener(); |
||||
|
|
||||
///
|
///
|
||||
|
|
||||
function setupResizeListener() { |
function setupResizeListener() { |
||||
const RESIZE_CODE = 'resize:'; |
const resizeObserver = new ResizeObserver((entries) => setTimeout(handleHeightChange, 100)); |
||||
|
resizeObserver.observe(document.body); |
||||
|
} |
||||
|
|
||||
const resizeObserver = new ResizeObserver(entries => { |
function handleHeightChange(entries) { |
||||
const height = document.querySelector('body > main').scrollHeight; |
const updatedHeight = getCurrentHeight(); |
||||
window.parent.postMessage(RESIZE_CODE + JSON.stringify({height}), '*'); |
if (height === updatedHeight) { |
||||
}) |
return; |
||||
|
} |
||||
|
|
||||
resizeObserver.observe(document.body); |
const RESIZE_CODE = 'resize:'; |
||||
|
window.parent.postMessage(RESIZE_CODE + JSON.stringify({height}), '*'); |
||||
|
height = updatedHeight; |
||||
|
} |
||||
|
|
||||
|
function getCurrentHeight() { |
||||
|
return document.querySelector('body > main').scrollHeight; |
||||
} |
} |
||||
|
|||||
Loading…
Reference in new issue