原生JS实现非常好看的计数器

发布时间:2022-04-16 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了原生JS实现非常好看的计数器脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

今天给大家分享一个用原生JS实现的好看计数器,效果如下:

以下是代码实现,欢迎大家复制粘贴和收藏。

<!DOCTYPE htML>
<html lang="en">
 
<head>
    <;meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, inITial-scale=1.0">
    <title>原生JS实现一个好看计数器</title>
    <style>
        * {
            font-family: '微软雅黑', sans-serif;
            box-sizing: border-box;
            margin: 0;
            padding: 0;
        }
 
        body {
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            background: #000d0f;
        }
 
        .container {
            position: relative;
            width: 80px;
            height: 50px;
            border-radius: 40px;
            border: 2px solid rgba(255, 255, 255, 0.2);
            transition: 0.5s;
        }
 
        .container:hover {
            width: 120px;
            border: 2px solid rgba(255, 255, 255, 1);
        }
 
        .container .next {
            position: absolute;
            top: 50%;
            right: 30px;
            display: block;
            width: 12px;
            height: 12px;
            border-top: 2px solid #fff;
            border-left: 2px solid #fff;
            z-index: 1;
            transform: translateY(-50%) rotate(135deg);
            cursor: pointer;
            transition: 0.5s;
            opacity: 0;
        }
 
        .container:hover .next {
            opacity: 1;
            right: 20px;
        }
 
        .container .prev {
            position: absolute;
            top: 50%;
            left: 30px;
            display: block;
            width: 12px;
            height: 12px;
            border-top: 2px solid #fff;
            border-left: 2px solid #fff;
            z-index: 1;
            transform: translateY(-50%) rotate(315deg);
            cursor: pointer;
            transition: 0.5s;
            opacity: 0;
        }
 
        .container:hover .PRev {
            opacity: 1;
            left: 20px;
        }
 
        #box span {
            position: absolute;
            display: none;
            width: 100%;
            height: 100%;
            text-align: center;
            line-height: 46px;
            color: #00deff;
            font-Size: 24px;
            font-weight: 700;
            user-select: none;
        }
 
        #box span:nth-child(1) {
            display: initial;
        }
    </style>
</head>
 
<body>
    <div class="container">
        <div class="next" onclick="nextNum()"></div>
        <div class="prev" onclick="prevNum()"></div>
        <div id="box">
            <span>0</span>
        </div>
    </div>
 
    <script>
        VAR numbers = document.getElementById('box')
        for (let i = 0; i < 100; i++) {
            let span = document.createElement('span')
            span.textContent = i
            numbers.appendChild(span)
        }
        let num = numbers.getelementsbytagname('span')
        let index = 0
 
        function nextNum() {
            num[index].style.display = 'none'
            index = (index + 1) % num.length
            num[index].style.display = 'initial'
        }
        function prevNum() {
            num[index].style.display = 'none'
            index = (index - 1 + num.length) % num.length
            num[index].style.display = 'initial'
        }
    </script>
</body>
 
</html>
@H_304_10@

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本宝典。

脚本宝典总结

以上是脚本宝典为你收集整理的原生JS实现非常好看的计数器全部内容,希望文章能够帮你解决原生JS实现非常好看的计数器所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签:jsjs