给博客网站顶部增加一排小桔灯增添夜间氛围[代码]

非常喜庆个性的一个美化,有点非常的闪亮,不是一般人都能接受的,默认出现时间为晚8点到早8点,距离顶部为50px;可以根据自己的需求修改。配合网站每天自动夜间模式效果非常好。

图片[1]-给博客网站顶部增加一排小桔灯增添夜间氛围[代码]-楊仙森万事坞

使用教程:

以Wordpress为例把下面的代码加入到主题目录下function.php中

add_filter('wp_footer', 'add_lu_xiaojudeng');
function add_lu_xiaojudeng() {
  date_default_timezone_set("Asia/Shanghai");
  $curTime = date("Y-m-d H:i:s",time());
  $stimestamp = date("Y-m-d H:i:s",mktime(8,0,0,date("m"),date("d"),date("Y"))); //早上8点。
  $etimestamp = date("Y-m-d H:i:s",mktime(20,0,0,date("m"),date("d"),date("Y"))); //晚上8点。
if(($curTime >= $stimestamp & $curTime <=$etimestamp)== false){
   echo'
    <div id="xiaojudeng">
   </div>
<script type="text/javascript">
var con = document.getElementById("xiaojudeng");
var width=document.body.clientWidth;
var j = Math.ceil(width/15) + 1;
for(var i=0; i<=j; i++){
       var crli = document.createElement("li");
    con.appendChild(crli);
}
</script>';
}
}

CSS代码加入到主题自定义CSS代码里面:

#xiaojudeng{
            position: fixed;
            z-index: 999;
            top: 50px; //到顶部的距离。
            pointer-events: none;
            width: 100%;
            height: 120px;
            white-space: nowrap;
            overflow: hidden;
        }
        #xiaojudeng li{
            display: inline-block;
            margin-top: 15px;
            margin-right: 50px;
            width: 15px;
            height: 30px;
            border-radius: 50%;
            position: relative;
        }
        #xiaojudeng li::after{
            content: '';
            position: absolute;
            top: -5px;
            left: 50%;
            transform: translateX(-50%);
            width: 20px;
            height: 12px;
            background-color: #727472;
            box-shadow: inset 0 0 3px #c3c3bd;
            border-radius: 10px;

        }
        #xiaojudeng li::before{
            content: '';
            position: absolute;
            top: -23px;
            left: 15px;
            width: 55px;
            height: 30px;
            border-bottom: 3px solid  #e7e7e7;
            border-radius: 50%;
        }
        #xiaojudeng li:nth-of-type(2n+1){
           animation: lan 2s  infinite;
        }#xiaojudeng li:nth-child(2n+2){
            animation: huang 2.2s infinite;
        }#xiaojudeng li:nth-child(3n+3){
            animation: zhi 1.8s infinite;
        }
       #xiaojudeng li:nth-child(4n+4){
        animation: lv 2.8s infinite;
       }

        @keyframes lan{
            0%,100%{
                background-color: rgba(4, 255, 242, 0.5);
            }
            50%{
                background-color: rgb(4, 255, 242);
                box-shadow: 0 0 10px rgb(4, 255, 242),
                0 0 30px rgb(4, 255, 242),
                0 0 50px rgb(4, 255, 242);
            }
        }
        @keyframes huang{
            0%,100%{
                background-color: rgba(251, 255, 4,.5);
            }
            50%{
                background-color: rgb(251, 255, 4);
                box-shadow: 0 0 10px rgb(251, 255, 4),
                0 0 12px rgb(251, 255, 4),
                0 0 30px rgb(251, 255, 4);
            }
        }
        @keyframes lv{
            0%,100%{
                background-color: rgba(33, 255, 4,.5);
            }
            50%{
                background-color: rgb(33, 255, 4);
                box-shadow: 0 0 10px rgb(33, 255, 4),
                0 0 12px rgb(33, 255, 4),
                0 0 30px rgb(33, 255, 4);
            }
        }
        @keyframes zhi{
            0%,100%{
                background-color:  rgba(255, 4, 255,.5);
            }
            50%{
                background-color: rgb(255, 4, 255);
                box-shadow: 0 0 10px  rgb(255, 4, 255),
                0 0 25px  rgb(255, 4, 255),
                0 0 40px  rgb(255, 4, 255);
            }
        }

 

温馨提示:本文最新于2023-11-02 22:45:13进行了更新,某些文章内容具有时效性,若失效或有错误,请在下方留言
© 版权声明
THE END
点赞22投币 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容