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

推荐订阅源

腾讯CDC
IT之家
IT之家
有赞技术团队
有赞技术团队
WordPress大学
WordPress大学
Apple Machine Learning Research
Apple Machine Learning Research
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
人人都是产品经理
人人都是产品经理
The Cloudflare Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
博客园 - 【当耐特】
V
V2EX
Last Week in AI
Last Week in AI
H
Help Net Security
The GitHub Blog
The GitHub Blog
S
SegmentFault 最新的问题
F
Fortinet All Blogs
I
InfoQ
宝玉的分享
宝玉的分享
A
About on SuperTechFans
MongoDB | Blog
MongoDB | Blog
Microsoft Azure Blog
Microsoft Azure Blog
Blog — PlanetScale
Blog — PlanetScale
B
Blog

博客园 - 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)  评论()    收藏  举报