css3怎麼實現圍繞圓心公轉

藏色散人
發布: 2023-01-31 10:17:13
原創
2059 人瀏覽過

css3實作圍繞圓心公轉的方法:1、建立一個HTML範例檔案;2、定義一個div;3、透過「.out {border-radius: 150px;background-color: sandybrown;... 」屬性設定外層圓;4、使用animation和transform等屬性定義基點並實現圍繞圓心公轉即可。

css3怎麼實現圍繞圓心公轉

本教學操作環境:Windows10系統、CSS3版、DELL G3電腦

css3怎麼實作圍繞圓心公轉?

CSS3動畫表情包圍繞圓公轉而而不自轉

效果如圖

css3怎麼實現圍繞圓心公轉

<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>公转不自转</title>
  <style>
    /* 外层圆 */
    .out {
      margin-top: 200px;
      margin-left: 200px;
      position: relative;
      height: 300px;
      width: 300px;
      border-radius: 150px;
      background-color: sandybrown;
      box-shadow: 0 0 23px;
    }
    /* 笑脸的容纳框 */
    .cover {
      display: inline-block;
      width: 50px;
      height: 50px;
      position: absolute;
      /* 定义基点 */
      transform-origin: 150px 150px;
      animation: smile linear 5s infinite;
      background-color: springgreen;
    }
    /* 笑脸表情包*/
    img {
      width: 50px;
      height: 50px;
      /*方法1 不自转只需要reverse反向线性就可以了*/
      animation: smile reverse linear 5s infinite;
    }
    @keyframes smile {
      to {
        transform: rotateZ(360deg);
      }
    }
    /* 方法2 */
    /* 默认情况下笑脸会跟随容纳框再5s内旋转360deg,所以只要再变换曲线相同的情况下再让它倒着转360deg就好啦 */
    /* @keyframes no-rotate {
      to {
        transform: rotateZ(-360deg);
      }
    } */
    /* 文本的绝对居中 */
    .out span {
      display: block;
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      font-size: 20px;
    }
  </style>
</head>
<body>
  <div>
    <div>
      <img
        src="https://ss0.bdstatic.com/94oJfD_bAAcT8t7mm9GUKT-xh_/timg?image&quality=100&size=b4000_4000&sec=1577100031&di=7445f215ef1f860d45fd93be22b52f57&src=http://git.oschina.net/uploads/group/110103951448978.jpg"
        alt="">
    </div>
    <span>和蔼的笑脸</span>
  </div>
</body>
</html>
登入後複製

推薦學習:《css影片教學

以上是css3怎麼實現圍繞圓心公轉的詳細內容。更多資訊請關注PHP中文網其他相關文章!

相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!