码迷,mamicode.com
首页 > 其他好文 > 详细

transform布局不会脱离文档流

时间:2018-11-23 22:00:21      阅读:1146      评论:0      收藏:0      [点我收藏+]

标签:cli   document   log   title   link   client   href   var   htm   

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>

transform布局不会脱离文档流

标签:cli   document   log   title   link   client   href   var   htm   

原文地址:https://www.cnblogs.com/gaollard/p/10009858.html

(1)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!