[英]How to toggle the viewport of webpage using a button in react
Im trying to make my website change view from mobile to desktop view using a button in javascript我试图让我的网站使用 javascript 中的按钮将视图从移动视图更改为桌面视图
const handleClick = () => {
const viewport = document.querySelector("meta[name=viewport]")
viewport.setAttribute(
"content",
"width=200px, initial-scale=1.0, maximum-scale=2.0, user-scalable=0",
)
}
I am using this code and it changes the viewport in html when I inspect using chrome but the screen is not changing我正在使用此代码,当我使用 chrome 检查时它会更改 html 中的视口,但屏幕没有改变
我想,你不能像我们在 html 中那样直接在 react js 中使用 document.queryselector,而是必须使用 useRef 和 ref 来访问 DOM 元素。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.