3D css3空间转换平移
- <title>空间平移</title>
- <style>
- .box {
- width: 200px;
- height: 200px;
- margin: 100px auto;
- background-color: pink;
- transition: all 0.5s;
- }
- .box:hover {
- /* 电脑是平面,默认无法观察 Z 轴平移效果 */
- /* transform: translate3d(100px, 200px, 300px); */
- /* 3d 小括号里面必须逗号隔开三个数 */
- /* transform: translate3d(100px, 200px); */
- transform: translateX(100px);
- transform: translateY(-100%);
- transform: translateZ(300px);
- }
- </style>
复制代码
- <title>透视效果</title>
- <style>
- /* 视距属性必须添加给 直接父级 */
- .father {
- perspective: 1000px;
- /* perspective: 10000px;
- perspective: 100px; */
- }
- .son {
- width: 200px;
- height: 200px;
- margin: 100px auto;
- background-color: pink;
- transition: all 0.5s;
- }
- .son:hover{
- transform: translateZ(-300px);
- transform: translateZ(300px);
- }
- </style>
- </head>
- <body>
- <div class="father">
- <div class="son"></div>
- </div>
- </body>
复制代码
- <title>空间旋转-Z轴</title>
- <style>
- .box {
- width: 300px;
- margin: 100px auto;
- }
- img {
- width: 300px;
- transition: all 2s;
- }
- .box img:hover {
- transform: rotateZ(360deg);
- }
- </style>
- </head>
- <body>
- <div class="box">
- <img src="./images/hero.jpeg" alt="" />
- </div>
- </body>
复制代码
- <title>空间旋转-X轴</title>
- <style>
- .box {
- width: 300px;
- margin: 100px auto;
- }
- img {
- width: 300px;
- transition: all 2s;
- }
- .box {
- /* 透视效果:近大远小,近实远虚 */
- perspective: 1000px;
- }
- .box img:hover {
- transform: rotateX(60deg);
- transform: rotateX(-60deg);
- }
- </style>
- </head>
- <body>
- <div class="box">
- <img src="./images/hero.jpeg" alt="" />
- </div>
- </body>
复制代码
- <title>空间旋转-Y轴</title>
- <style>
- .box {
- width: 300px;
- margin: 100px auto;
- }
- img {
- width: 300px;
- transition: all 2s;
- }
- .box {
- /* 透视效果:近大远小,近实远虚 */
- perspective: 1000px;
- }
- .box img:hover {
- transform: rotateY(60deg);
- transform: rotateY(-60deg);
- }
- </style>
- </head>
- <body>
- <div class="box">
- <img src="./images/hero.jpeg" alt="" />
- </div>
- </body>
复制代码
|