【发布时间】:2023-04-04 22:40:01
【问题描述】:
当用户在 iOS 中进行捏合缩小时,我们希望将其返回到正常视图(100%)
由于我们的项目,我们不能使用touchstart或touchmove
我们在下面有这段代码,但不起作用。
document.addEventListener('touchend', function(event) {
if (window.visualViewport.scale != 1) {
document.body.style.transform = 'scale(1)';
}
}, {passive: false});
我们也试过了,
document.body.style.zoom = 1;
在捏缩放时,我们是否可以强制返回 100% 缩放?任何帮助将不胜感激。
完整的 HTML 代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
<script>
document.addEventListener('touchend', function(event) {
if (window.visualViewport.scale != 1) {
document.body.style.transform = 'scale(1)';
//document.body.style.zoom = 1;
//window.visualViewport.scale = 1;
}
}, {
passive: false
});
</script>
<style>
html,
body {
width: 100%;
height: 100%;
background-color: green;
overflow: hidden;
}
</style>
</head>
<body>
</body>
</html>
【问题讨论】:
-
您希望用户根本无法缩放吗?
-
@learningtoanimate 是的,但我们不能使用 touchstart 或 touchmove
标签: javascript css ios mobile