网站建设定制开发transform-origin属性详解

 网站建设定制开发用于设置动画的基点(中心点) , 网站建设定制开发适用于所有块级元素及某些内联元素。

        必须配合transform使用  默认情况下,元素的动作参考点为元素盒子的中心

       可以设置九个位置的值:水平方向:  left    center      right

                                                                    0       50%       100%

                                               垂直方向:  top    center     bottom

        默认值:50% 50% ,相对于center center

        两种写法 ,

         eg:

                transform-origin: left; 

                transform-origin:0;

                  

语法:

transform-origin: x-axis y-axis z-axis;

属性值详解

  1. <div class="outer">
  2. <div class="inner"></div>
  3. <div class="inner"></div>
  4. </div>

1.默认值,以自身原点旋转45deg

  1. .outer {
  2. width: 100px;
  3. height: 100px;
  4. background-color: #6a5acd8c;
  5. margin: 200px;
  6. position: relative;
  7. }
  8. /* (1)默认值旋转,红色为基点 默认值为 transform-origin: 50% 50% 0;*/
  9. .inner {
  10. transform: rotate(45deg);
  11. /* transform-origin: 50% 50% 0; */
  12. width: 100%;
  13. height: 100%;
  14. background-color: #6a5acdeb;
  15. }
  16. .outer .inner:nth-child(2){
  17. width: 5px;
  18. height: 5px;
  19. background-color: red;
  20. transform: none;
  21. position: absolute;
  22. top: 50px;
  23. left: 50px;
  24. }

2.以顶部旋转180deg

  1. .outer {
  2. width: 100px;
  3. height: 100px;
  4. background-color: #6a5acd8c;
  5. margin: 200px;
  6. position: relative;
  7. }
  8. /* (2)以顶部旋转180deg */
  9. .inner {
  10. transform: rotate(180deg);
  11. transform-origin: 50% 0;
  12. width: 100%;
  13. height: 100%;
  14. background-color: #6a5acdeb;
  15. }
  16. .inner:nth-child(2) {
  17. width: 5px;
  18. height: 5px;
  19. background-color: red;
  20. transform: none;
  21. position: absolute;
  22. top: -2.5px;
  23. left: 50px;
  24. }

 

3.以右部旋转150deg

  1. /* 以右部旋转150deg 红色为基点 */
  2. .inner {
  3. transform: rotate(150deg);
  4. transform-origin: 100% 50%;
  5. width: 100%;
  6. height: 100%;
  7. background-color: #6a5acdeb;
  8. }
  9. .inner:nth-child(2) {
  10. width: 5px;
  11. height: 5px;
  12. background-color: red;
  13. transform: none;
  14. position: absolute;
  15. top: 47.5px;
  16. left: 97.5px;
  17. }

4.左上角旋转20deg 红色为基点

  1. .inner {
  2. transform: rotate(-20deg);
  3. transform-origin: 0 0;
  4. width: 100%;
  5. height: 100%;
  6. background-color: #6a5acdeb;
  7. }
  8. .inner:nth-child(2) {
  9. width: 5px;
  10. height: 5px;
  11. background-color: red;
  12. transform: none;
  13. position: absolute;
  14. top: -2.5px;
  15. left: -2.5px;
  16. }

从以上例子中可以看出,属性值的所代表的偏移位置,了解各属性值所代表的偏移位置后可以很灵活得使元素按照某一基准点进行旋转。

网站建设定制开发 软件系统开发定制 定制软件开发 软件开发定制 定制app开发 app开发定制 app开发定制公司 电商商城定制开发 定制小程序开发 定制开发小程序 客户管理系统开发定制 定制网站 定制开发 crm开发定制 开发公司 小程序开发定制 定制软件 收款定制开发 企业网站定制开发 定制化开发 android系统定制开发 定制小程序开发费用 定制设计 专注app软件定制开发 软件开发定制定制 知名网站建设定制 软件定制开发供应商 应用系统定制开发 软件系统定制开发 企业管理系统定制开发 系统定制开发