{"id":13671504,"url":"https://github.com/ustbhuangyi/animation","last_synced_at":"2025-04-05T09:07:55.151Z","repository":{"id":14055694,"uuid":"16758604","full_name":"ustbhuangyi/animation","owner":"ustbhuangyi","description":"an common animation lib","archived":false,"fork":false,"pushed_at":"2020-10-01T06:52:32.000Z","size":338,"stargazers_count":316,"open_issues_count":3,"forks_count":149,"subscribers_count":18,"default_branch":"master","last_synced_at":"2025-03-29T08:05:35.521Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://ustbhuangyi.github.io/animation/demo/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ustbhuangyi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-02-12T06:47:04.000Z","updated_at":"2025-02-09T04:48:40.000Z","dependencies_parsed_at":"2022-09-26T20:00:43.583Z","dependency_job_id":null,"html_url":"https://github.com/ustbhuangyi/animation","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ustbhuangyi%2Fanimation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ustbhuangyi%2Fanimation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ustbhuangyi%2Fanimation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ustbhuangyi%2Fanimation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ustbhuangyi","download_url":"https://codeload.github.com/ustbhuangyi/animation/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247312080,"owners_count":20918344,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T09:01:11.288Z","updated_at":"2025-04-05T09:07:54.594Z","avatar_url":"https://github.com/ustbhuangyi.png","language":"JavaScript","readme":"animation\r\n=========\r\n\r\n[![npm](https://img.shields.io/npm/v/frame-animation.svg?style=flat-square)](https://www.npmjs.com/package/frame-animation)\r\n\r\n[例子在这里](http://ustbhuangyi.github.io/animation/demo/)\r\n\r\n通常我们会遇到一些需求，用js实现一组动画（这里指的是由一帧帧图片组合而成的动画，非jq的animate）。\r\n\r\n其实原理很简单，如果是多张图，就定时去改变image的src，如果是一张图，就定时改变backgroud-position；同时，我们还要支持图片预加载，动画执行次数（一次，n次，无限次），动画暂停，动画执行完成的回调等等。\r\n\r\n有了上述需求，我觉得写一个通用的animation库还是很有必要的，这样用户就每必要为每一组动画写逻辑了，从繁琐的劳动中解放，不正是每个coder所期望的么：）\r\n\r\n## Usage\r\n\r\n### npm 安装\r\n\r\n```\r\n$ npm install frame-animation\r\n```\r\n\r\n### 示例\r\n\r\n#### HTML\r\n\r\n```html\r\n\u003cdiv id=\"demo\"\u003e\u003c/div\u003e\r\n```\r\n\r\n#### CSS\r\n\r\n```css\r\n#demo {\r\n    width: 100px;\r\n    height: 100px;\r\n    background: url('foo.png');\r\n}\r\n```\r\n\r\n#### JavaScript\r\n\r\n``` javascript\r\nvar animation = require(\"frame-animation\");\r\n\r\nvar ele = document.getElementById('demo');\r\nvar frameMap = ['0 0', '0 -100', '0 -200'];\r\n    \r\nvar demoAnimation = animation().changePosition(ele, positions).repeat();\r\n    demoAnimation.start(200);\r\n\r\n```\r\n这种链式调用的语法，是不是很爽呢（妈妈再也不用担心我的动画）\r\n\r\n## animation提供的接口\r\n\r\n* loadImage(imagelist)  //预加载图片\r\n* changePosition(ele,positions)  //通过改变元素的backgroud-position实现动画\r\n* changeSrc(ele,imglist) //通过改变image元素的src实现动画(一般这种方式需要和loadImage配合使用)\r\n* then(callback) //动画执行完成后的回调函数\r\n* enterFrame(callback) //每一帧动画执行的函数，相当于用户可以自定义每一帧动画的callback\r\n* repeat(times) //动画重复执行的次数，times为空时表示无限次\r\n* repeatForever() //无限重复上一次动画, 相当于repeat()，更友好的一个接口吧\r\n* wait(time) //每个动画执行完后等待的时间\r\n* start(interval) //动画开始执行，interval表示动画执行的间隔\r\n* pause() //动画暂停\r\n* restart() //动画从上一次暂停处重新执行\r\n* dispose() //释放资源\r\n\r\n## 如何构建\r\nanimation的源码是基于webpack构建的\r\n\r\n首先，clone项目源码\r\n```bash\r\ngit clone https://github.com/ustbhuangyi/animation.git\r\n```\r\n\r\n安装依赖\r\n```bash\r\ncd animation\r\nnpm install\r\n```\r\n测试demo页\r\n\r\n```bash\r\nnpm run dev\r\n```\r\n打开浏览器访问如下地址, 查看效果\r\n\r\n\u003e localhost:9090\r\n","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fustbhuangyi%2Fanimation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fustbhuangyi%2Fanimation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fustbhuangyi%2Fanimation/lists"}