美文网首页
环形倒计时(抄袭别人的,用来学习)

环形倒计时(抄袭别人的,用来学习)

作者: 糖醋里脊120625 | 来源:发表于2022-08-23 10:26 被阅读0次
<html lang="zh">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
        content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <title>环形倒计时</title>
</head>

<body>

    <div class="flex-container">
        <div class="outbox"> </div>
        <!--  SVG AREA -->
        <svg class="svg">
            <circle id="cls" class="cls run-anim" cx="80" cy="80" r="75.5"></circle>
            <circle id="smallYuan" class="roundSmall fillStyle" cx="80" cy="4" r="4"></circle>
        </svg>
        <!--  SVG AREA END -->
        <div class="boxDIv">
            <div class="OutTime" id="OutTime"></div>
        </div>
    </div>
    <script>
        let TimeVal = 0.1; //传入分钟
        let entryTime = parseInt(new Date().getTime() / 1000);//进入页面的当前时间
        let currentTime = 0;//当前时间
        let maxtime = TimeVal * 60; // 分钟 * 60 = 最多走几秒
        let circle = document.getElementById('cls'); //获取大圆环
        let smallYuan = document.getElementById('smallYuan'); //获取小圆圈
        let total;//动画总时长
        let count = 0;//动画总时长
        function CountDown() {
            currentTime = parseInt(new Date().getTime() / 1000); //在定时器里面每隔一秒记录当前时间;
            let TimeDifference = (currentTime - entryTime); //时间差
            let mytime = maxtime - TimeDifference  //传入的秒数 - 已经走掉的秒数  = 当前还剩多少秒数
            if (TimeDifference <= maxtime) { //如果已经走掉的秒数 小于等于  传入的秒数
                minutes = Math.floor(mytime / 60);
                seconds = Math.floor(mytime % 60);
                console.log(minutes, seconds)
                if (seconds <= 9) {
                    seconds = '0' + seconds
                }
                if (minutes <= 9) {
                    minutes = '0' + minutes
                }
                msg = minutes + ":" + seconds;
                document.getElementById('OutTime').innerHTML = msg;
                if(count == 0){
                    circleTime();
                }
                count ++
            } else {
                count = 0;
                clearInterval(timer);
                console.log("时间到,结束!");
            }
        }
        
        function circleTime() {
            total = maxtime; 
            circle.style.animationDuration = total + "s";//动画时长
            circle.style.animationPlayState = "running";
            smallYuan.style.animationDuration = total + "s";//动画时长
            smallYuan.style.animationPlayState = "running";
            //动画播放状态 running:指定正在运行的动画
        
        }
        timer = setInterval("CountDown()", 1000);
    </script>
</body>


<style>
    * {
    margin: 0;
    padding: 0;
}

html {
    font: 100% "Montserrat Light", serif;
    height: 100vh;
    width: 100%;
    overflow: visible;
}

body {
    height: inherit;
    width: inherit;
}

.flex-container {
    width: 180px;
    height: 180px;
    margin: 0 auto;
   position: relative;
    background-color: #eeeeee;
    border-radius: 50%;
    color: #ffffff;
    margin-top: 100px;
}

.outbox {
    width: 85%;
    height: 85%;
    border-radius: 100%;
    background-color: #fff;
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
}

.svg {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 160px;
    height: 160px;
}

.cls {
    fill: none;
    stroke: #000;
    stroke-linecap: round;
    stroke-miterlimit: 10;
    stroke-width: 4px;
    stroke-dasharray: 475;
    /*stroke-dasharray:475;代表: 虚线长475,间距475,然后重复 虚线长475,间距475 */
    stroke-dashoffset: 475;/* 偏移量 */
    /* stroke-dashoffset: 475;  用半径 * 2 * 3.1415926  得出偏移量 475 */
    transform: rotate(270deg);
    transform-origin: 50% 50%;
}

.run-anim {
    -webkit-animation-name: dash;
    -moz-animation-name: dash;
    -o-animation-name: dash;
    animation-name: dash;
    animation-duration: 0s;
    animation-play-state: paused;
    animation-fill-mode: none;
    animation-iteration-count: 1;
    animation-timing-function: linear;
}

@keyframes dash {
    0% {
        stroke: #D65E9E;
        stroke-dashoffset: 0;
    }

    100% {
        stroke: #D65E9E;
        stroke-dashoffset: 475;
    }
}


.boxDIv {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    font-size: 38px;
    font-family: Source Han Sans CN;
    font-weight: bold;
    color: #333333;
}



.fillStyle{
    fill: #fff;
    transform: rotate(0deg);
    transform-origin: 50% 50%;
}
.roundSmall{
    stroke: #e1e1e1;
    -webkit-animation-name: rotate;
    -moz-animation-name: rotate;
    -o-animation-name: rotate;
    animation-name: rotate;
    animation-duration: 0s;
    animation-play-state: paused;
    animation-fill-mode: none;
    animation-iteration-count: 1;
    animation-timing-function: linear;
}

@keyframes rotate {
    0% {
        transform: rotate(-1deg);
    }

    100% {
        transform: rotate(-360deg);
    }
}
</style>

</html>

相关文章

  • 环形倒计时(抄袭别人的,用来学习)

  • canvas环形倒计时组件

    效果如下图一: Canvas环形倒计时组件 Canvas环形倒计时是基于Canvas实现的倒计时,建议于移动端使用...

  • 环形倒计时

    以前项目中有一个小小的需求,是圆形倒计时view,话不多说请看图  怎么实现这样的需求了? 圆形可以通过贝塞尔曲线...

  • svg动画(二)

    1.目标 实现一个环形倒计时的动画。 2.具体操作 2.1 画一个环形 上代码: 最后的效果图: 2.1.1 代码...

  • 控制流

    For循环 for循环用来按照指定的次数多次执行一系列语句。Swift 提供两种for循环形式: for-in用来...

  • 读书,发现美

    人长眼睛,是用来发现别人长处的,是用来学习别人长处的。要是它只是用来挑剔别人,惹来无穷烦恼,还不如瞎了好。 《活着...

  • 倒计时

    学习别人的一个方便快捷的倒计时实现 __block int timeout = time; //倒计时时间 dis...

  • 其实真正会写文章的人,往往都是从“抄袭”开始!

    首先声明,这里的抄袭并不是说让你一字不差的去抄袭别人的作品,而是要去学习别人作品优秀的地方,然后加入自己的原创亮点...

  • iOS 简单的环形倒计时

    提到倒计时或者时进度条 现在总有很多种样式 上一次我们搞了双曲线波浪 进度http://www.jianshu.c...

  • 为什么不能抄袭别人的文案?

    1、不经别人允许,抄袭别人的东西,就是盗窃! 2、是对别人极大的不尊重。 3、在互联网上不经允许,抄袭别人的文案,...

网友评论

      本文标题:环形倒计时(抄袭别人的,用来学习)

      本文链接:https://www.haomeiwen.com/subject/nbtggrtx.html