日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > CSS >内容正文

CSS

CSS学习记录9/3D的正方体的两种编写方式/3D长方体的编写方式/3D动画/3D播放器

發布時間:2023/12/20 CSS 47 豆豆
生活随笔 收集整理的這篇文章主要介紹了 CSS学习记录9/3D的正方体的两种编写方式/3D长方体的编写方式/3D动画/3D播放器 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

什么是2D什么是3D?
2D就是一個平面,只是寬度和高度,沒有厚度。
3D就是一個立體,有寬度有高度,還有厚度。
默認情況下所有的元素都是呈2D展現的。

如何讓某個元素呈3D展現?
和透視一樣,只需給該元素的父元素添加一個transform-style屬性,然后設置為preserve-3d即可。

正方體第一種方案:

ul{width: 200px;height: 200px;border: 1px solid #000;box-sizing: border-box;margin: 100px auto;position: relative;transform: rotateY(0deg) rotateX(0deg);transform-style: preserve-3d;}ul li{list-style: none;width: 200px;height: 200px;font-size: 60px;text-align: center;line-height: 200px;position: absolute;left: 0;top: 0;}ul li:nth-child(1){background-color: #ffada3;transform: translate(-100px) rotateY(90deg);}ul li:nth-child(2){background-color: #ffcaf3;transform: translate(100px) rotateY(90deg);}ul li:nth-child(3){transform: translateY(100px) rotateX(90deg);background-color: #cdcdcd;}ul li:nth-child(4){transform: translateY(-100px) rotateX(90deg);background-color: #67676d;}ul li:nth-child(5){transform: translateZ(-100px);background-color: cornflowerblue;}ul li:nth-child(6){transform: translateZ(100px);background-color: greenyellow;}


正方體第二種方案:前后上下內容不會翻轉。

ul li:nth-child(1){background-color: #ffada3;transform: rotateX(90deg) translateZ(100px) ;}ul li:nth-child(2){background-color: #ffcaf3;transform: rotateX(180deg) translateZ(100px);}ul li:nth-child(3){transform: rotateX(270deg) translateZ(100px) ;background-color: #cdcdcd;}ul li:nth-child(4){transform: rotateX(360deg) translateZ(100px);background-color: #67676d;}ul li:nth-child(5){transform: translateX(-100px) rotateY(90deg);background-color: cornflowerblue;}ul li:nth-child(6){transform: translateX(100px) rotateY(90deg);background-color: greenyellow;}/*上、后、下、前分別繞X軸旋轉90度、180度、270度、360度然后沿Z軸平移100像素*/


如何做一個長方體?
先做一個正方體,給需要拉寬的面設置scale參數。
例:scale(1.5,1)

3D動畫:

<!DOCTYPE html> <html lang="en"> <head><meta charset="UTF-8"><title>Title</title><style>body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,form,fieldset,input,textarea,p,blockquote,th,td {padding: 0;margin: 0;}body{perspective: 500px;/*近大遠小的效果*/}ul{width: 200px;height: 200px;box-sizing: border-box;margin: 100px auto;position: relative;transform: rotateY(0deg) rotateX(0deg);transform-style: preserve-3d;animation: move 5s linear 0s infinite normal;}@keyframes move {from{transform: rotateX(0deg);}to{transform: rotateX(360deg);}}ul li{list-style: none;width: 200px;height: 200px;font-size: 60px;text-align: center;line-height: 200px;position: absolute;left: 0;top: 0;}ul li img{width: 200px;height: 200px;/*只要父元素被拉伸了子元素也會被拉伸*/}ul li:nth-child(1){transform: rotateX(90deg) translateZ(100px) scale(1.5,1);}ul li:nth-child(2){transform: rotateX(180deg) translateZ(100px) scale(1.5,1);}ul li:nth-child(3){transform: rotateX(270deg) translateZ(100px) scale(1.5,1);}ul li:nth-child(4){transform: rotateX(360deg) translateZ(100px) scale(1.5,1);}ul li:nth-child(5){transform: translateX(-200px) rotateY(90deg);}ul li:nth-child(6){transform: translateX(200px) rotateY(90deg);}/*上、后、下、前分別繞X軸旋轉90度、180度、270度、360度然后沿Z軸平移100像素*//*長方體,給需要拉寬的面設置scale參數*/</style> </head> <body> <ul><li><img src="images/tp1"></li><li><img src="images/tp2"></li><li><img src="images/tp3"></li><li><img src="images/tp4"></li><li></li><li></li> </ul> </body> </html>

效果:
3D播放器:

<!DOCTYPE html> <html lang="en"> <head><meta charset="UTF-8"><title>3D播放器</title><style>body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,form,fieldset,input,textarea,p,blockquote,th,td {padding: 0;margin: 0;}body{background: url("images/qq3.jpg") no-repeat;background-size: cover;/*無論瀏覽器有多寬有多高都能填滿整個網頁*/overflow: hidden;}ul{width: 200px;height: 200px;/*background-color: #ffcaf3;*/position: absolute;bottom: 100px;left: 50%;margin-left: -100px;transform-style: preserve-3d;/*transform: rotateX(-10deg);*/animation: move 6s linear 0s infinite normal ;}/*鼠標懸停在ul上時,動畫暫停*/ul:hover{animation-play-state: paused;}/*鼠標懸停在ul時,所有圖片變透明*/ul:hover li img{opacity: 0.5;}/*鼠標懸停在li上時,圖片不透明,放大1.5倍*/ul li:hover img{opacity: 1;transform: scale(1.5);}@keyframes move {from{transform: rotateX(-10deg) rotateY(0deg);}to{transform: rotateX(-10deg) rotateY(360deg);}/*1、動畫中如果有和默認樣式同名的屬性,會覆蓋默認樣式2、在編寫動畫的時候,固定不變的值寫在前面,需要變化的值寫在后面。*/}ul li{list-style: none;width: 200px;height: 200px;font-size: 60px;line-height: 200px;text-align: center;position: absolute;left: 0;top: 0;}ul li img{width: 200px;height: 200px;border: 5px solid darkcyan;box-sizing: border-box;}ul li:nth-child(1){background-color: black;transform: rotateY(60deg) translateZ(200px);}ul li:nth-child(2){background-color: black;transform: rotateY(120deg) translateZ(200px);}ul li:nth-child(3){background-color: black;transform: rotateY(180deg) translateZ(200px);}ul li:nth-child(4){background-color: black;transform: rotateY(240deg) translateZ(200px);}ul li:nth-child(5){background-color: black;transform: rotateY(300deg) translateZ(200px);}ul li:nth-child(6){background-color: black;transform: rotateY(360deg) translateZ(200px);}.tree{width: 200px;height: 200px;position: absolute;left: 100px;bottom: 100px;animation: move1 20s linear 0s infinite normal;}/*愛心移動軌跡*/@keyframes move1 {0%{left: 100px;bottom: 100px;opacity: 1;}20%{left: 550px;bottom: 600px;opacity: 0;}40%{left: 900px;bottom: 650px;opacity: 1;}60%{left: 1200px;bottom: 500px;opacity: 0;}80%{left: 1400px;bottom: 200px;opacity: 1;}90%{left: 1650px;bottom: 100px;opacity: 0;}100%{left: 1250px;bottom: 50px;opacity: 1;}}/*設置播放器的位置*/div{width: 300px;height: 100px;margin: 400px auto;}</style> </head> <body> <ul><li><img src="images/fj"></li><li><img src="images/fj2"></li><li><img src="images/fj3"></li><li><img src="images/fj4"></li><li><img src="images/fj3"></li><li><img src="images/fj2"></li> </ul> <img src="images/xiaotubiao.png" class="tree"> <div><audio src="images/好聽的歌.mp3" autoplay="autoplay" loop controls="controls"></audio> </div></body> </html>

結果:動畫在主頁視頻里

總結

以上是生活随笔為你收集整理的CSS学习记录9/3D的正方体的两种编写方式/3D长方体的编写方式/3D动画/3D播放器的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。