1. 程式人生 > >用css做一個旋轉的地球儀

用css做一個旋轉的地球儀

html部分:

<body>
    <div class="hoder"></div>
    <div class="circle"></div>
    <div class="circle equator"></div>
    <div class="circle weft1"></div>
    <div class="circle weft2"></div>
    <div class="circle weft3"></div>
    <
div class="circle weft3"></div> <div class="circle weft4"></div> <div class="hoder2"></div> <div class="bottom"></div> <div class="bottom2"></div> </body>

球的部分是將div的邊框置為圓形

將圓圈進行3D旋轉,就得到一個選裝的透視球

transform: rotateX(70deg) translateZ(

70px);

這個是將圓圈平躺下,做成赤道的樣子

其餘的weft是緯線,通過3D的Y軸變換得到

然後再做靜態的支架即可

執行結果如下:


原始碼如下:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>努力做個地球儀</title>
    <style>
        body{
            background-color: black;
        }
        .circle{
            border-radius
: 100%; height: 100px; width: 100px; left: 200px; top: 200px; position: absolute; border: 1px solid #394057; transform-style: preserve-3d; } .equator{ top:260px; transform: rotateX(70deg) translateZ(70px) } .weft1{ -webkit-animation-duration:10s; -webkit-animation-iteration-count: infinite; -webkit-animation-timing-function: linear; -webkit-animation-name:weft1; } .weft2{ -webkit-animation-duration:10s; -webkit-animation-iteration-count: infinite; -webkit-animation-timing-function: linear; -webkit-animation-name:weft2; } .weft3{ -webkit-animation-duration:10s; -webkit-animation-iteration-count: infinite; -webkit-animation-timing-function: linear; -webkit-animation-name:weft3; } .weft4{ -webkit-animation-duration:10s; -webkit-animation-iteration-count: infinite; -webkit-animation-timing-function: linear; -webkit-animation-name:weft4; } .hoder{ height: 159px; width: 100px; left: 150px; top: 180px; position: absolute; border-right:2px solid #394057 ; } .hoder2{ border-radius: 100%; border-left:3px solid #394057 ; height: 140px; width: 140px; top:180px; left: 180px; position: absolute; } .bottom{ height:100px; width: 100px; border-radius: 100%; left: 200px; top: 355px; position: absolute; transform-style: preserve-3d; transform: rotateX(70deg) translateZ(70px); z-index: -100; border:2px solid #394057 ; } .bottom2{ height:10px; width: 10px; border-radius: 100%; left: 244px; top: 397px; position: absolute; transform-style: preserve-3d; transform: rotateX(70deg) translateZ(70px); z-index: -100; border:2px solid #394057 ; } @-webkit-keyframes weft1{ from{ -webkit-transform:rotateY(40deg); } to{ -webkit-transform:rotateY(400deg); } } @-webkit-keyframes weft2{ from{ -webkit-transform:rotateY(80deg); } to{ -webkit-transform:rotateY(440deg); } } @-webkit-keyframes weft3{ from{ -webkit-transform:rotateY(120deg); } to{ -webkit-transform:rotateY(480deg); } } @-webkit-keyframes weft4{ from{ -webkit-transform:rotateY(160deg); } to{ -webkit-transform:rotateY(520deg); } } </style> </head> <body> <div class="hoder"></div> <div class="circle"></div> <div class="circle equator"></div> <div class="circle weft1"></div> <div class="circle weft2"></div> <div class="circle weft3"></div> <div class="circle weft3"></div> <div class="circle weft4"></div> <div class="hoder2"></div> <div class="bottom"></div> <div class="bottom2"></div> </body> </html>