{"id":43500387,"url":"https://github.com/zhanziyang/better-interval","last_synced_at":"2026-02-03T11:20:00.396Z","repository":{"id":97947140,"uuid":"70697600","full_name":"zhanziyang/better-interval","owner":"zhanziyang","description":"It is like setInterval but better, because it uses requestAnimationFrame.","archived":false,"fork":false,"pushed_at":"2017-06-20T03:46:33.000Z","size":21,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-10T13:12:52.965Z","etag":null,"topics":["loop","performance","requestanimationframe","setinterval"],"latest_commit_sha":null,"homepage":"https://zhanziyang.github.io/better-interval/","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/zhanziyang.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-10-12T12:27:05.000Z","updated_at":"2018-07-16T16:07:08.000Z","dependencies_parsed_at":"2023-07-20T04:15:54.728Z","dependency_job_id":null,"html_url":"https://github.com/zhanziyang/better-interval","commit_stats":{"total_commits":22,"total_committers":1,"mean_commits":22.0,"dds":0.0,"last_synced_commit":"8c5f9278600a2fee4e45dff88ec8b45cf3beeb3f"},"previous_names":["zhanziyang/looprequest"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/zhanziyang/better-interval","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhanziyang%2Fbetter-interval","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhanziyang%2Fbetter-interval/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhanziyang%2Fbetter-interval/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhanziyang%2Fbetter-interval/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zhanziyang","download_url":"https://codeload.github.com/zhanziyang/better-interval/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhanziyang%2Fbetter-interval/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29044106,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-03T10:09:22.136Z","status":"ssl_error","status_checked_at":"2026-02-03T10:09:16.814Z","response_time":96,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["loop","performance","requestanimationframe","setinterval"],"created_at":"2026-02-03T11:19:59.720Z","updated_at":"2026-02-03T11:20:00.387Z","avatar_url":"https://github.com/zhanziyang.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# BetterInterval\nIt works similar to `setInterval`, but under the hood it uses \u003ccode\u003erequestAnimationFrame\u003c/code\u003e to achieve the same goal. So it's less buggy.\n\n### NOTICE\n* Works in browsers, not on servers.\n* Supports CommonJS, so you can use it with tools like Browserify or Webpack.\n\n### Why not just use setInterval?\n- setInterval keeps running event when the browser tab or window is not active.\n- When the callback function takes longer to finish than the interval you set, it will not wait for the function thus resulting in enqueuing of multiple callback functions.\n\nSee more: [Better Performance With requestAnimationFrame](https://dev.opera.com/articles/better-performance-with-requestanimationframe/) by Luz Caballero\n\n## Quck Start\n### 1. Download\n```html\n\u003cscript src=\"https://unpkg.com/better-interval/dist/better-interval.min.js\"\u003e\u003c/script\u003e\n```\nor if you use module bundler such as Browserify:\n```cmd\nnpm install --save better-interval\n```\n### 2. Import\n\n```javascript\nvar BetterInterval = require(\"better-interval\");\n```\nor\n```js\nimport BetterInterval from 'better-interval'\n```\n\n## Usage\n### Constructor\n```js\nvar betterInterval = new BetterInterval(callback [, interval] [, ...args])\n```\n#### callback: \n- Repetitively executing function\n- type: `function`\n#### interval:\n- Time gap between each loop. By default it matches the display refresh rate of browser, which usually is 60 fps. So it's default value is approximately 16.7 (≈1000/60)\n- type: `number` (milliseconds)\n- optional\n#### args:\n- The rest arguments. They will be passed in to the callback.\n\n### Methods:\n- Start looping\n```js\nbetterInterval.set()\n```\n\n- Stop looping\n```js\nbetterInterval.clear()\n```\n\n## Example\n\n- Use BetterInterval to make a moving box animation. It moves 3 pixels per 100 milliseconds until the offset reaches 1000.\n\n```javascript\nvar box = document.querySelector(\"#box\");\nvar offset = 0;\n\nvar betterInterval = new BetterInterval(function (increment, max) {\n  offset += increment;\n  box.style.left = offset + \"px\";\n\n  if (offset \u003e= max) {\n    betterInterval.clear()\n  }\n}, 100, 3, 1000);\n\nbetterInterval.set()\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzhanziyang%2Fbetter-interval","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzhanziyang%2Fbetter-interval","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzhanziyang%2Fbetter-interval/lists"}