惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

A
About on SuperTechFans
小众软件
小众软件
WordPress大学
WordPress大学
Microsoft Azure Blog
Microsoft Azure Blog
Recent Announcements
Recent Announcements
博客园 - 三生石上(FineUI控件)
博客园_首页
N
Netflix TechBlog - Medium
IT之家
IT之家
H
Help Net Security
博客园 - 聂微东
Google DeepMind News
Google DeepMind News
罗磊的独立博客
T
Tailwind CSS Blog
F
Fortinet All Blogs
Hugging Face - Blog
Hugging Face - Blog
MongoDB | Blog
MongoDB | Blog
V
V2EX
量子位
云风的 BLOG
云风的 BLOG
爱范儿
爱范儿
博客园 - 司徒正美
The Cloudflare Blog
Engineering at Meta
Engineering at Meta

博客园 - howhy

TypeScript any vs unknown 详细对比 TypeScript interface vs type 完整对比 html 元素包含关系 this 指向 空对象 Object.keys for ...in Reflect.ownKeys ...区别 逻辑运算符和空值运算符 运算符优先级 js 类型显式转换 js 高级函数 js 方法重载 fetch timeout js 任务顺序执行 暂停 js 并发任务 判断两个对象是否相同 js 动态拦截属性 js groupby js 防抖和节流 实现 instanceof 操作符 js 单例模式 js 数组去重和扁平方法 js 继承方法 js new的过程实现 js deepCopy js '=='的隐性类型转换规则
js 通用动画
howhy · 2025-12-31 · via 博客园 - howhy
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin:0;
            padding:0;
            box-sizing: border-box;
        }
        .box{
            margin: 200px;
        }
        .circle_outter{
            width: 200px;
            height: 200px;
            border: 1px solid;
            border-radius: 50%;
            display: flex;
            justify-content: center;
            align-items: center;
            background-color: antiquewhite;
        }
        .circle_inner{
            width: 100px;
            height: 100px;
            border: 1px solid;
            border-radius: 50%;
            background-color: #fff;
            display: flex;
            justify-content: center;
            align-items: center;
            position: relative;
        }
        .circle_inner>div{
            position: absolute;
            display: flex;
            justify-content: center;
        }
        .circle_inner>div:nth-child(2){
            color:red;
            transform: rotate(0deg) translate(0px, -75px) rotate(-0deg);
        }
        .circle_inner>div:nth-child(3){
            color:red;
            transform: rotate(0deg) translate(75px) rotate(-0deg);
        }
        .circle_inner>div:nth-child(4){
            color:red;
            transform: rotate(0deg) translate(0,75px) rotate(-0deg);
        } 
        .circle_inner>div:nth-child(5){
            color:red;
            transform: rotate(0deg) translate(-75px) rotate(-0deg);
        }
    </style>
</head>
<body>
    <div class="box">
    <div class="circle_outter">
        <div class="circle_inner">
            <div class="home">#</div>
            <div>1</div>
            <div>2</div>
            <div>3</div>
            <div>4</div>
        </div>
    </div>
    <button class="btn">打折</button>
    <label for="">价格:6699.00</label>
    </div>
    <script src="./b.js"></script>
    <script>
        function animation(duration,from,to,handler){
            let value=from;
            const speed=(to-from)/duration;
            const startTime=Date.now();
            function _run(){
                const t=Date.now()-startTime;
                if(t>=duration){
                value=to;
                handler(value);
                return;
                }
                value=from+t*speed;
                handler(value);
                requestAnimationFrame(_run);
            }
            _run();
        }
        const label=document.querySelector('label');
        const btn=document.querySelector('.btn');
        btn.onclick=function(){
            animation(2000,6699,30,(value)=>{
                label.textContent=`价格:${value}`
            });
        }
    </script>
</body>
</html>

posted @ 2025-12-31 10:05  howhy  阅读(52)  评论()    收藏  举报