Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
cheton authored Sep 7, 2017
1 parent 907b755 commit ac231c0
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,15 @@ If you want to avoid polling, use [MutationObserver](https://developer.mozilla.o
const iframe = ReactDOM.findDOMNode(node);
iframe.addEventListener('load', () => {
const target = iframe.contentDocument.body;

// Recalculate the height of the content
iframe.style.height = 0;
const nextHeight = target.scrollHeight;
iframe.style.height = `${nextHeight}px`;

this.timer = setInterval(() => {
// Recalculate the height of the content
iframe.style.height = 0;
const nextHeight = target.scrollHeight;
iframe.style.height = `${nextHeight}px`;
}, 200);
Expand All @@ -79,19 +84,27 @@ If you want to avoid polling, use [MutationObserver](https://developer.mozilla.o
const iframe = ReactDOM.findDOMNode(node);
iframe.addEventListener('load', () => {
const target = iframe.contentDocument.body;
const config = {
attributes: true,
attributeOldValue: false,
characterData: true,
characterDataOldValue: false,
childList: true,
subtree: true
};

// Recalculate the height of the content
iframe.style.height = 0;
const nextHeight = target.scrollHeight;
iframe.style.height = `${nextHeight}px`;

this.observer = new MutationObserver(mutations => {
// Recalculate the height of the content
iframe.style.height = 0;
const nextHeight = target.scrollHeight;
iframe.style.height = `${nextHeight}px`;
});
this.observer.observe(target, {
attributes: true,
childList: true,
characterData: true,
subtree: true
});
this.observer.observe(target, config);
});
}}
src="iframe.html"
Expand Down

0 comments on commit ac231c0

Please sign in to comment.