溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

怎么用css實(shí)現(xiàn)3d動(dòng)畫特效

發(fā)布時(shí)間:2022-02-28 15:32:00 來源:億速云 閱讀:393 作者:小新 欄目:web開發(fā)

小編給大家分享一下怎么用css實(shí)現(xiàn)3d動(dòng)畫特效,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!

  屬性

  perspective:透距離,單位像素(值越小,透視距離越近,效果越明顯):設(shè)置父元素上

  perspective-origin:設(shè)置透視點(diǎn)的位置

  transform-style:指定某元素的子元素是位于三維空間內(nèi),取值:flat|preserve-3d

  1.1.1思路

 ?。?)有三個(gè)p,一起放到一個(gè)盒子里面。

  <pclass="container">

  <pclass="cube">

  <pclass="mianmian1"></p>

  <pclass="mianmian2"></p>

  <pclass="mianmian3"></p>

  </p>

  </p>

 ?。?)為其盒子設(shè)置樣式

  .cube{

  width:200px;

  height:300px;

  transform-style:preserve-3d;

  margin:100pxauto;

  position:relative;

  transform:rotateX(30deg);

  border-radius:50%;

  padding:60px;

  }

  (3)為其每個(gè)p設(shè)置樣式

  .mian{

  width:200px;

  height:300px;

  background-image:url(1.jpg);

  background-position:400px0;

  position:absolute;

  background:url(aka.jpg);

  border:1pxsolid#ccc;

  transition:2s;

  }

  /*.mian1:hover{

  transform-origin:right;

  transform:rotateY(-60deg);

  }*/

  .mian1{

  transform-origin:right;

  transform:translateX(-200px)rotateY(45deg);

  background-position:00;

  }

  .mian2{

  background-position:400px0;

  }

  .mian3{

  transform-origin:left;

  transform:translateX(200px)rotateY(45deg);

  background-position:200px0;

  }

 ?。?)為其設(shè)置動(dòng)畫

  .mian3:hover{

  transform:translateX(200px)rotateY(0deg);

  }

  .mian1:hover{

  transform:translateX(-200px)rotateY(0deg);

  }

  1.1.1源碼:

  <!DOCTYPEhtml>

  <htmllang="en">

  <head>

  <metacharset="UTF-8">

  <metaname="viewport"content="width=device-width,initial-scale=1.0">

  <metahttp-equiv="X-UA-Compatible"content="ie=edge">

  <title>書頁</title>

  <style>

  .container{

  width:1000px;

  height:650px;

  perspective:2000px;

  border:1pxsolidtransparent;

  overflow:hidden;

  margin:0auto;

  perspective-origin:10%20%;

  }

  .cube{

  width:200px;

  height:300px;

  transform-style:preserve-3d;

  margin:100pxauto;

  position:relative;

  transform:rotateX(30deg);

  border-radius:50%;

  padding:60px;

  }

  .mian{

  width:200px;

  height:300px;

  background-image:url(1.jpg);

  background-position:400px0;

  position:absolute;

  background:url(aka.jpg);

  border:1pxsolid#ccc;

  transition:2s;

  }

  /*.mian1:hover{

  transform-origin:right;

  transform:rotateY(-60deg);

  }*/

  .mian1{

  transform-origin:right;

  transform:translateX(-200px)rotateY(45deg);

  background-position:00;

  }

  .mian2{

  background-position:400px0;

  }

  .mian3{

  transform-origin:left;

  transform:translateX(200px)rotateY(45deg);

  background-position:200px0;

  }

  .mian3:hover{

  transform:translateX(200px)rotateY(0deg);

  }

  .mian1:hover{

  transform:translateX(-200px)rotateY(0deg);

  }

  </style>

  </head>

  <body>

  <pclass="container">

  <pclass="cube">

  <pclass="mianmian1"></p>

  <pclass="mianmian2"></p>

  <pclass="mianmian3"></p>

  </p>

  </p>

  </body>

  </html>

  1.1.2

  2094583391-5b70f66722968_articlex.gif

  1.1.2思路:

 ?。?)有五個(gè)p,分別放上五個(gè)字。

  <pid="box">

  <pclass="ze1">前</p>

  <pclass="ze2">端</p>

  <pclass="ze3">小</p>

  <pclass="ze4">學(xué)</p>

  <pclass="ze5">生</p>

  </p>

 ?。?)給box和p總體設(shè)置樣式

  #box{

  margin:100pxauto;

  font-size:100px;

  color:#005aa0;

  text-align:center;

  }

  .ze1,.ze2,.ze3,.ze4,.ze5{

  display:inline-block;

  width:90px;

  height:100%;

  position:relative;

  }

 ?。?)設(shè)置偽元素before和after

  .ze1:before,.ze2:before,.ze3:before,.ze4:before,.ze5:before{

  content:attr(data);

  position:absolute;

  color:#ffffff;

  top:0;

  left:2px;

  transform-origin:left;

  transition:transform.5s;

  }

  .ze1:before{

  content:"前";

  }

  .ze2:before{

  content:"端";

  }

  .ze3:before{

  content:"小";

  }

  .ze4:before{

  content:"學(xué)";

  }

  .ze5:before{

  content:"生";

  }

  .ze1:after,.ze2:after,.ze3:after,.ze4:after,.ze5:after{

  position:absolute;

  color:#b3b3b3;

  top:3px;

  left:10px;

  z-index:-1;

  transform-origin:left;

  transition:transform.5s;

  }

  .ze1:after{

  content:"前";

  }

  .ze2:after{

  content:"端";

  }

  .ze3:after{

  content:"小";

  }

  .ze4:after{

  content:"學(xué)";

  }

  .ze5:after{

  content:"生";

  }

 ?。?)為其設(shè)置動(dòng)畫

  .ze1:hover:before,.ze2:hover:before,.ze3:hover:before,.ze4:hover:before,.ze5:hover:before{

  transform:rotateY(-40deg)skewY(10deg);

  }

  .ze1:hover:after,.ze2:hover:after,.ze3:hover:after,.ze4:hover:after,.ze5:hover:after{

  transform:rotateY(40deg)skewY(10deg);

  }

  1.1.2源碼:

  <!DOCTYPEhtml>

  <htmllang="en">

  <head>

  <metacharset="UTF-8">

  <title>動(dòng)態(tài)字</title>

  <style>

  #box{

  margin:100pxauto;

  font-size:100px;

  color:#005aa0;

  text-align:center;

  }

  .ze1,.ze2,.ze3,.ze4,.ze5{

  display:inline-block;

  width:90px;

  height:100%;

  position:relative;

  }

  .ze1:before,.ze2:before,.ze3:before,.ze4:before,.ze5:before{

  content:attr(data);

  position:absolute;

  color:#ffffff;

  top:0;

  left:2px;

  transform-origin:left;

  transition:transform.5s;

  }

  .ze1:before{

  content:"前";

  }

  .ze2:before{

  content:"端";

  }

  .ze3:before{

  content:"小";

  }

  .ze4:before{

  content:"學(xué)";

  }

  .ze5:before{

  content:"生";

  }

  .ze1:after,.ze2:after,.ze3:after,.ze4:after,.ze5:after{

  position:absolute;

  color:#b3b3b3;

  top:3px;

  left:10px;

  z-index:-1;

  transform-origin:left;

  transition:transform.5s;

  }

  .ze1:after{

  content:"前";

  }

  .ze2:after{

  content:"端";

  }

  .ze3:after{

  content:"小";

  }

  .ze4:after{

  content:"學(xué)";

  }

  .ze5:after{

  content:"生";

  }

  .ze1:hover:before,.ze2:hover:before,.ze3:hover:before,.ze4:hover:before,.ze5:hover:before{

  transform:rotateY(-40deg)skewY(10deg);

  }

  .ze1:hover:after,.ze2:hover:after,.ze3:hover:after,.ze4:hover:after,.ze5:hover:after{

  transform:rotateY(40deg)skewY(10deg);

  }

  </style>

  </head>

  <body>

  <pid="box">

  <pclass="ze1">前</p>

  <pclass="ze2">端</p>

  <pclass="ze3">小</p>

  <pclass="ze4">學(xué)</p>

  <pclass="ze5">生</p>

  </p>

  </body>

  </html>

  1.1.3思路不寫,只寫源碼

  1.1.3源碼:

  <!DOCTYPEhtml>

  <htmllang="en">

  <head>

  <metacharset="UTF-8">

  <metaname="viewport"content="width=device-width,initial-scale=1.0">

  <metahttp-equiv="X-UA-Compatible"content="ie=edge">

  <title>3d動(dòng)畫</title>

  <style>

  body{

  margin:0;

  background:url(iom.jpg);

  background-size:100%;

  position:relative;

  }

  .box{

  width:430px;

  height:430px;

  position:absolute;;

  top:100px;

  left:480px;

  border:1pxsolid#ccc;

  border-radius:215px;

  text-align:center;

  animation:dong20sinfinitelinear;

  }

  .ai{

  width:10px;

  height:10px;

  background:#0c0;

  border-radius:5px;

  position:absolute;

  right:38px;

  top:340px;

  }

  @keyframesdong{

  0%{

  transform:rotate(0deg)

  }

  100%{

  transform:rotate(720deg)

  }

  }

  .mrin{

  width:320px;

  height:320px;

  border:1pxsolid#ccc;

  border-radius:180px;

  position:absolute;

  top:155px;

  left:535px;

  animation:mi15sinfinitelinear;

  }

  .ak{

  width:50px;

  height:50px;

  border:1pxsolid#ccc;

  margin:20px0020px;

  border-radius:25px;

  display:inline-block;

  animation:ol5sinfinitelinear;

  }

  .ak.sj1{

  width:10px;

  height:10px;

  border-radius:5px;

  margin:20px0020px;

  background:blue;

  }

  .ak.sj2{

  width:10px;

  height:10px;

  margin-top:5px;

  background:#fff;

  border-radius:5px;

  }

  @keyframesmi{

  0%{

  transform:rotate(0deg)

  }

  100%{

  transform:rotate(720deg)

  }

  }

  @keyframesol{

  0%{

  transform:rotate(0deg)

  }

  100%{

  transform:rotate(720deg)

  }

  }

  .mian{

  width:240px;

  height:240px;

  border:1pxsolid#ccc;

  position:absolute;

  border-radius:120px;

  top:195px;

  left:575px;

  animation:af5sinfinitelinear;

  }

  .mian.ap{

  width:10px;

  height:10px;

  border-radius:5px;

  background:#f0f;

  margin:30px0030px;

  }

  @keyframesaf{

  0%{

  transform:rotate(0deg)

  }

  100%{

  transform:rotate(720deg)

  }

  }

  .chen{

  width:160px;

  height:160px;

  border:1pxsolid#ccc;

  position:absolute;

  border-radius:80px;

  top:235px;

  left:615px;

  animation:oa4sinfinitelinear;

  }

  .ze{

  width:10px;

  height:10px;

  border-radius:5px;

  background:#0c0;

  margin:20px0015px;

  }

  @keyframesoa{

  0%{

  transform:rotate(0deg)

  }

  100%{

  transform:rotate(720deg)

  }

  }

  .yu{

  width:80px;

  height:80px;

  background-color:darkorange;

  border-radius:40px;

  position:absolute;

  top:275px;

  left:655px;

  opacity:.7;

  }

  </style>

  </head>

  <body>

  <pclass="box">

  <pclass="ai"></p>

  </p>

  <pclass="mrin">

  <pclass="ak">

  <pclass="sj1"></p>

  <pclass="sj2"></p>

  </p>

  </p>

  <pclass="mian">

  <pclass="ap"></p>

  </p>

  <pclass="chen">

  <pclass="ze"></p>

  </p>

  <pclass="yu"></p>

  </body>

  </html>

  .ak.sj2{

  width:10px;

  height:10px;

  margin-top:5px;

  background:#fff;

  border-radius:5px;

  }

  @keyframesmi{

  0%{

  transform:rotate(0deg)

  }

  100%{

  transform:rotate(720deg)

  }

  }

  @keyframesol{

  0%{

  transform:rotate(0deg)

  }

  100%{

  transform:rotate(720deg)

  }

  }

  .mian{

  width:240px;

  height:240px;

  border:1pxsolid#ccc;

  position:absolute;

  border-radius:120px;

  top:195px;

  left:575px;

  animation:af5sinfinitelinear;

  }

  .mian.ap{

  width:10px;

  height:10px;

  border-radius:5px;

  background:#f0f;

  margin:30px0030px;

  }

  @keyframesaf{

  0%{

  transform:rotate(0deg)

  }

  100%{

  transform:rotate(720deg)

  }

  }

  .chen{

  width:160px;

  height:160px;

  border:1pxsolid#ccc;

  position:absolute;

  border-radius:80px;

  top:235px;

  left:615px;

  animation:oa4sinfinitelinear;

  }

  .ze{

  width:10px;

  height:10px;

  border-radius:5px;

  background:#0c0;

  margin:20px0015px;

  }

  @keyframesoa{

  0%{

  transform:rotate(0deg)

  }

  100%{

  transform:rotate(720deg)

  }

  }

  .yu{

  width:80px;

  height:80px;

  background-color:darkorange;

  border-radius:40px;

  position:absolute;

  top:275px;

  left:655px;

  opacity:.7;

  }

  </style>

  </head>

  <body>

  <pclass="box">

  <pclass="ai"></p>

  </p>

  <pclass="mrin">

  <pclass="ak">

  <pclass="sj1"></p>

  <pclass="sj2"></p>

  </p>

  </p>

  <pclass="mian">

  <pclass="ap"></p>

  </p>

  <pclass="chen">

  <pclass="ze"></p>

  </p>

  <pclass="yu"></p>

  </body>

  </html>

怎么用css實(shí)現(xiàn)3d動(dòng)畫特效

以上是“怎么用css實(shí)現(xiàn)3d動(dòng)畫特效”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

css
AI