resizedCallback is called too early
See original GitHub issueHi, for some reason my iFrame is resized 2 times during the page load and second time it is resized with message different from init
and in the code I can see that in this case resizing happens inside requestAnimationFrame(say I use Chrome) which is basically async. But the callback is called synchronously.
...
default:
resizeIFrame();
callback('resizedCallback',messageData);
}
function resizeIFrame(){
function resize(){
setSize(messageData);
setPagePosition(iframeId);
}
ensureInRange('Height');
ensureInRange('Width');
syncResize(resize,messageData,'init');
}
function syncResize(func,messageData,doNotSync){
/* istanbul ignore if */ //Not testable in PhantomJS
if(doNotSync!==messageData.type && requestAnimationFrame){
log(messageData.id,'Requesting animation frame');
requestAnimationFrame(func);
} else {
func();
}
}
Finally I wrap my callback function into requestAnimationFrame
which works as expected but that should be mentioned in docs if not changes in the source code. I would like to help with the fix but have no idea why you put requestAnimationFrame
here. Thanks.
Issue Analytics
- State:
- Created 7 years ago
- Comments:9 (4 by maintainers)
Top Results From Across the Web
3026 (resizable resize handler is called too early) - jQuery UI
The resizable resize callback is called before the element is resized, and before the position and size properties (which are passed as ui.position...
Read more >How to wait for the 'end' of 'resize' event and only then perform ...
When a user resizes a window manually (by dragging it) the resize event will be called more than once, so using .one() really...
Read more >ResizeObserver: it's like document.onresize for elements
ResizeObserver notifies you when an element's content rectangle changes size so that you can react accordingly.
Read more >How To Use the Resize Observer JavaScript API - DigitalOcean
In this post we'll see how we can use the new ResizeObserver API to react to an element's size changing.
Read more >Window: resize event - Web APIs | MDN
onresize to control the time after which the event fires. Syntax. Use the event name in methods like addEventListener() , or set an...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I am experiencing the same issue as @dshiryaev-plesk. I believe the resized callback should only be called once the resize is done:
Calling back inside the
resizeIFrame
function even looks a bit cleaner to me.Would you accept this change?
I had the same issue with iframeresizer where the page loaded too quickly and triggered the javascript before it was ready after switching to a cdn for faster loading times.
The fix was to wrap the call on the onload with the javascript setTimeout function to delay loading by one second (setTimeout(iframeresizer({}),1000); (add the params you need)… You can also set the width and height using the style tag to set the width/height larger than the space you need then it should show correctly after a second… i don’t notice the difference.