默认情况下,iframe会自带滚动条,不会全屏;想自适应iframe的方法
- 第一步,去掉滚动条
- 第二步,设置iframe的高为body的高
iframe的用法技巧 https://www.yuque.com/lulongwen/web/cs332b
import React, { useLayoutEffect, useRef, useState } from 'react';
const initStyle = { width: '100%', height: '100%' };
function InnerFrame() {
const frameRef = useRef();
const [style, setStyle] = useState(initStyle);
useLayoutEffect(() => {
const height = document.body.offsetHeight;
setStyle({...initStyle, height });
}, []);
return (
<iframe
ref={frameRef}
src="https://www.baidu.com"
id="website"
title="website"
scrolling="no"
frameBorder='0'
style={style}
/>
);
}
export default InnerFrame;