這篇文章主要介紹“html5如何實(shí)現(xiàn)三維效果”,在日常操作中,相信很多人在html5如何實(shí)現(xiàn)三維效果問(wèn)題上存在疑惑,小編查閱了各式資料,整理出簡(jiǎn)單好用的操作方法,希望對(duì)大家解答”html5如何實(shí)現(xiàn)三維效果”的疑惑有所幫助!接下來(lái),請(qǐng)跟著小編一起來(lái)學(xué)習(xí)吧!
創(chuàng)新互聯(lián)-專(zhuān)業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性價(jià)比壺關(guān)網(wǎng)站開(kāi)發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫(kù),直接使用。一站式壺關(guān)網(wǎng)站制作公司更省心,省錢(qián),快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋壺關(guān)地區(qū)。費(fèi)用合理售后完善,十余年實(shí)體公司更值得信賴(lài)。
html5實(shí)現(xiàn)三維效果的方法:1、創(chuàng)建一個(gè)HTML示例文件;2、通過(guò)“.img {width: 50px;height: 50px;margin: 0 auto;transform-style: preserve-3d;}”屬性實(shí)現(xiàn)三維立體效果;3、通過(guò)“@-webkit-keyframes rotate {...}”屬性實(shí)現(xiàn)動(dòng)畫(huà)效果即可。
基于Css3的一些新特性拼接而成.主要用到了hover,transform和@keyframe屬性.下面簡(jiǎn)述一下這三個(gè)屬性的作用.
hover
效果:當(dāng)鼠標(biāo)移到元素上時(shí)會(huì)展現(xiàn)你定義的hover的樣式
使用方法:假定我們有一個(gè)類(lèi),名為mystyle.修改它的css樣式的方式是.mystyle{}.修改它的css hover樣式的方式是.mystyle:hover{}.
transform
效果:對(duì)元素進(jìn)行旋轉(zhuǎn)、縮放、移動(dòng)或傾斜
使用方法:傳入旋轉(zhuǎn)rotate(angle),縮放scale(x,y),移動(dòng)translate(x,y),傾斜skew(angle)的參數(shù)進(jìn)行屬性的修改
@keyframe
效果:實(shí)現(xiàn)動(dòng)畫(huà)效果
使用方法:@keyframe 后+動(dòng)畫(huà)名{from:初始狀態(tài);to:末狀態(tài)}
代碼解析
<style> /*實(shí)現(xiàn)立體效果*/
.img {
width: 50px;
height: 50px;
margin: 0 auto;
transform-style: preserve-3d;
/*設(shè)置動(dòng)畫(huà)播放樣式:動(dòng)畫(huà)對(duì)象 播放速度 時(shí)間 播放次數(shù)*/
animation: rotate linear 20s infinite;
} /*實(shí)現(xiàn)動(dòng)畫(huà)效果*/
@-webkit-keyframes rotate { /*sofari chrome*/
from {
transform: rotateX(0deg) rotateY(0deg);
}
to {
transform: rotateX(360deg) rotateY(360deg);
}
} /*圖片樣式*/
.pic{
width: 200px;
height: 200px;
transform: rotateY(0deg) translateZ(100px);
}</style>
接下來(lái)是特效實(shí)現(xiàn)的完整代碼
<div class="wrap">
<!--部署內(nèi)外層圖片-->
<div class="cube">
<!--前面圖片 -->
<div class="out_front">
<img src="/upload/otherpic55/efebb79001a49eda20069a1c0c9bb4e2-0.jpeg" class="pic">
</div>
<!--后面圖片 -->
<div class="out_back">
<img src="/upload/otherpic55/5bb5f23ce7f1e.jpg" class="pic">
</div>
<!--左面圖片 -->
<div class="out_left">
<img src="/upload/otherpic55/5bb5f26e13b28.jpg" class="pic">
</div>
<!--右面圖片 -->
<div class="out_right">
<img src="/upload/otherpic55/ed16de6f96fb6f509ffd3d176caceca2-3.jpg" class="pic">
</div>
<!--上面圖片 -->
<div class="out_top">
<img src="/upload/otherpic55/5bb5f2725c5c7.jpg" class="pic">
</div>
<!--下面圖片 -->
<div class="out_bottom">
<img src="/upload/otherpic55/0c1647c0eaf3fedf452e32840e68b09c-5.jpg" class="pic">
</div>
<!--小正方體 -->
<span class="in_front">
<img src="/upload/otherpic55/5bb9b2e441d7a.jpg" class="in_pic">
</span>
<span class="in_back">
<img src="/upload/otherpic55/5bb9b2e712b3f.jpg" class="in_pic">
</span>
<span class="in_left">
<img src="/upload/otherpic55/5bb9b2e86ad25.jpg" class="in_pic">
</span>
<span class="in_right">
<img src="/upload/otherpic55/5bb9b2eaba148.jpg" class="in_pic">
</span>
<span class="in_top">
<img src="/upload/otherpic55/5bb9b2ebe5bd9.jpg" class="in_pic">
</span>
<span class="in_bottom">
<img src="/upload/otherpic55/5bb9b2ed867be.jpg" class="in_pic">
</span>
</div>
<style> /*最外層容器樣式*/
.wrap {
width: 100px;
height: 100px;
margin: 150px;
position: relative;
} /*得到立方體效果*/
.cube {
width: 50px;
height: 50px;
margin: 0 auto;
transform-style: preserve-3d; /*設(shè)置動(dòng)畫(huà)播放樣式:動(dòng)畫(huà)對(duì)象 播放速度 時(shí)間 播放次數(shù)*/
animation: rotate linear 20s infinite;
} /*動(dòng)畫(huà)旋轉(zhuǎn)的方式*/
/*得到動(dòng)畫(huà)效果*/
@-moz-keyframes rotate { /*firefox*/
from {
transform: rotateX(0deg) rotateY(0deg);
}
to {
transform: rotateX(360deg) rotateY(360deg);
}
}
@-webkit-keyframes rotate { /*sofari chrome*/
from {
transform: rotateX(0deg) rotateY(0deg);
}
to {
transform: rotateX(360deg) rotateY(360deg);
}
}
@-o-keyframes rotate { /*opera*/
from {
transform: rotateX(0deg) rotateY(0deg);
}
to {
transform: rotateX(360deg) rotateY(360deg);
}
} /*每張圖片的樣式*/
.cube div {
position: absolute;
width: 200px;
height: 200px;
opacity: 0.8; /*過(guò)渡效果*/
transition: all .4s;
} /*定義所有圖片樣式*/
.pic {
width: 200px;
height: 200px;
}
.cube .out_front {
transform: rotateY(0deg) translateZ(100px);
}
.cube .out_back {
transform: translateZ(-100px) rotateY(180deg);
}
.cube .out_left {
transform: rotateY(-90deg) translateZ(100px);
}
.cube .out_right {
transform: rotateY(90deg) translateZ(100px);
}
.cube .out_top {
transform: rotateX(90deg) translateZ(100px);
}
.cube .out_bottom {
transform: rotateX(-90deg) translateZ(100px);
} /*定義小正方體樣式*/
.cube span {
display: block;
width: 100px;
height: 100px;
position: absolute;
top: 50px;
left: 50px;
}
.cube .in_pic {
width: 100px;
height: 100px;
}
.cube .in_front {
transform: rotateY(0deg) translateZ(50px);
}
.cube .in_back {
transform: translateZ(-50px) rotateY(180deg);
}
.cube .in_left {
transform: rotateY(-90deg) translateZ(50px);
}
.cube .in_right {
transform: rotateY(90deg) translateZ(50px);
}
.cube .in_top {
transform: rotateX(90deg) translateZ(50px);
}
.cube .in_bottom {
transform: rotateX(-90deg) translateZ(50px);
} /*鼠標(biāo)移入后樣式*/
.cube:hover .out_front {
transform: rotateY(0deg) translateZ(200px);
}
.cube:hover .out_back {
transform: translateZ(-200px) rotateY(180deg);
}
.cube:hover .out_left {
transform: rotateY(-90deg) translateZ(200px);
}
.cube:hover .out_right {
transform: rotateY(90deg) translateZ(200px);
}
.cube:hover .out_top {
transform: rotateX(90deg) translateZ(200px);
}
.cube:hover .out_bottom {
transform: rotateX(-90deg) translateZ(200px);
}
</style>
</div>
到此,關(guān)于“html5如何實(shí)現(xiàn)三維效果”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識(shí),請(qǐng)繼續(xù)關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編會(huì)繼續(xù)努力為大家?guī)?lái)更多實(shí)用的文章!
網(wǎng)站標(biāo)題:html5如何實(shí)現(xiàn)三維效果
文章出自:http://vcdvsql.cn/article48/gjshhp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供域名注冊(cè)、用戶體驗(yàn)、全網(wǎng)營(yíng)銷(xiāo)推廣、品牌網(wǎng)站建設(shè)、云服務(wù)器、網(wǎng)站導(dǎo)航
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)