transform布局不会脱离文档流
transform布局不会脱离文档流,也不改变文档流的大小和位置。
- width
- offsetWidth
- clientWidth
- offsetLeft
- ...
设置元素的 transform 属性后,上述等属性均不会发生改变
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title></title>
<link rel="stylesheet" href="">
<style>
* {
padding: 0;
margin: 0;
}
.box {
width: 200px;
height: 200px;
background-color: red;
}
</style>
</head>
<body>
<div class="box">box</div>
</body>
<script>
var box = document.querySelector(‘.box‘)
console.log(box.offsetWidth) // 200
console.log(box.offsetLeft) // 0
box.style.transform = ‘translate3d(10px, 10px, 0)‘
console.log(box.offsetWidth) // 200
console.log(box.offsetLeft) // 0
</script>
</html>
原文地址:https://www.cnblogs.com/gaollard/p/10009858.html
时间: 2024-10-10 18:03:07