console
document.addEventListener('DOMContentLoaded', () => {
const iframe = document.createElement('iframe');
iframe.setAttribute('sandbox', 'allow-scripts allow-same-origin');
iframe.style.width = '100%';
iframe.style.height = '100%';
const iframeContainer = document.querySelector('.iframe-container');
iframeContainer.appendChild(iframe);
iframe.contentWindow.document.body.style.overflow = 'hidden';
const style = document.createElement('style');
style.textContent = `
html, body {
touch-action: auto;
}
`;
iframe.contentWindow.document.head.appendChild(style);
const inner = document.createElement('div');
inner.style.cssText = `
height: 100%;
overflow: auto;
// overscroll-behavior: none;
-webkit-overflow-scrolling: touch;
`;
iframe.contentWindow.document.body.appendChild(inner);
const container = document.createElement('div');
document.body.appendChild(container);
const arr = new Array(20).fill(0);
arr.forEach((_, i) => {
const item1 = document.createElement('li');
item1.textContent = `iframe 第 ${i+1} 项`;
inner.append(item1);
const item2 = document.createElement('li');
item2.textContent = `外部 第 ${i+1} 项`;
container.append(item2);
});
});
<div class="iframe-container"></div>
.iframe-container {
-webkit-overflow-scrolling: touch;
width: 100%;
height: 100%;
}