分类目录归档:CSS

CSS

css 如何绘制一个地球,太阳,月亮等小行星的运行轨迹呢?


摘要:
下文讲述使用css脚本绘制一个太阳系动画的方法分享,如下所示:

例:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <style>
            body{
                background: black;
                overflow: hidden;
            }
            .sun{
                width: 150px;
                height: 150px;
                position: absolute;
                left: 50%;
                top: 50%;
                transform: translate(-50%,-50%);
                background: yellow;
                box-shadow: 0 0 30px 3px gold;
                border-radius: 50%;
            }
            .earth{
                width: 350px;
                height: 350px;
                position: absolute;
                left: 50%;
                top: 50%;
                /*居中*/
                transform: translate(-50%,-50%);
                border: 1px solid #ccc;
                border-radius: 50%;
                animation: rot 8s linear infinite;
            }
            .earth::before{
                content: "";
                width: 40px;
                height: 40px;
                position: absolute;
                left: 0;
                top: 50%;
                transform: translate(-50%,-50%);
                background: dodgerblue;
                border-radius: 50%;
            }
            .moon{
                width: 80px;
                height: 80px;
                position: absolute;
                left: 0;
                top: 50%;
                transform: translate(-50%,-50%);
                border-radius: 50%;
                animation: rot 2s linear infinite;
            }
            .moon::before{
                content: "";
                width: 10px;
                height: 10px;
                position: absolute;
                left: 0;
                top: 50%;
                transform: translate(-50%,-50%);
                background: #fff;
                border-radius: 50%;
            }
            .venus{
                width: 500px;
                height: 500px;
                position: absolute;
                left: 50%;
                top: 50%;
                transform: translate(-50%,-50%);
                border: 1px solid #ccc;
                border-radius: 50%;
                animation: rot 6s linear infinite;
            }
            .venus::before{
                content: "";
                width: 30px;
                height: 30px;
                position: absolute;
                left: 0;
                top: 50%;
                transform: translate(-50%,-50%);
                background: red;
                border-radius: 50%;
            }
            .mars{
                width: 600px;
                height: 600px;
                position: absolute;
                left: 50%;
                top: 50%;
                transform: translate(-50%,-50%);
                border: 1px solid #ccc;
                border-radius: 50%;
                animation: rot 10s linear infinite;
            }
            .mars::before{
                content: "";
                width: 50px;
                height: 50px;
                position: absolute;
                left: 0;
                top: 50%;
                transform: translate(-50%,-50%);
                background: pink;
                border-radius: 50%;
            }
            @keyframes rot{
                0%{
                    transform:translate(-50%,-50%) rotate(0deg);
                }
                100%{
                    transform:translate(-50%,-50%) rotate(360deg);
                }
            }
        </style>
    </head>
    <body>
        <div class="sun">
            <div class="earth">
                <div class="moon"></div>
            </div>
        </div>
        <div class="venus"></div>
        <div class="mars"></div>
        
    </body>
</html>
 
css绘制太阳系动画示例分享

css绘制太阳系动画示例分享

javascript 如何禁用link的css文件呢?


摘要:
下文讲述使用javascript脚本禁用外部链接的css文件的方法分享,如下所示:

实现思路: 
    使用DOM中styleSheets中的disabled属性即可使用外部导入的css文件禁用

例:

  
   <html>
    <head>
        <link id="cssFile1" rel="stylesheet" href="#" disabled />
        <script>
            window.onload = function()
            {
               
               document.getElementById('cssFile1').setAttribute('disabled'); //禁用css

               document.getElementById('cssFile1').removeAttribute('disabled'); //启用css
            }
        </script>
    </head>
    <body>
        <p>猫猫教程</p>
    </body>
</html>