Skip to content

Commit becff8d

Browse files
committed
Compensate for scrolling when showing an iframe above the viewport
1 parent b5fc294 commit becff8d

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

html/js/ejs.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,16 @@ window.addEventListener("load", function() {
152152
function placeFrame(frame, snippet) {
153153
var wrap = snippet.previousSibling;
154154
if (!wrap || wrap.className != "editor-wrap") {
155+
var bot = snippet.getBoundingClientRect().bottom;
155156
activateCode(snippet, null, "text/html");
156157
wrap = snippet.previousSibling;
158+
} else {
159+
bot = wrap.getBoundingClientRect().bottom;
157160
}
158161
wrap.insertBefore(frame, wrap.childNodes[1]);
162+
if (bot < 50) {
163+
var newBot = wrap.getBoundingClientRect().bottom;
164+
window.scrollBy(0, newBot - bot);
165+
}
159166
}
160167
});

html/js/sandbox.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,17 +89,15 @@
8989
return "";
9090
});
9191

92-
this.frame.style.height = "10px";
92+
this.frame.style.height = "80px";
9393
this.resizeFrame();
9494
if (scriptTags.length) {
9595
if (output) this.output = output;
9696
this.startedAt = Date.now();
9797
this.extraSecs = 1;
9898
this.win.__c = 0;
99-
var resize = doc.createElement("script");
100-
resize.innerHTML = "__sandbox.resizeFrame();";
101-
scriptTags.push(resize);
10299
scriptTags.forEach(function(tag) { doc.body.appendChild(tag); });
100+
setTimeout(this.resizeFrame.bind(this), 50);
103101
}
104102
},
105103
resizeFrame: function() {

0 commit comments

Comments
 (0)