{"id":19011543,"url":"https://github.com/codeabinash/scroll-observer","last_synced_at":"2026-02-26T20:03:51.121Z","repository":{"id":64871124,"uuid":"538095069","full_name":"codeAbinash/scroll-observer","owner":"codeAbinash","description":"A JavaScript library to animate easily elements on scroll into view","archived":false,"fork":false,"pushed_at":"2022-12-16T17:34:23.000Z","size":164,"stargazers_count":26,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-01T21:46:26.114Z","etag":null,"topics":["javascript-library","scroll-observer","scrollview"],"latest_commit_sha":null,"homepage":"https://codeabinash.github.io/scroll-observer/example/","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/codeAbinash.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-09-18T11:59:52.000Z","updated_at":"2025-01-01T08:26:27.000Z","dependencies_parsed_at":"2022-12-17T01:31:08.714Z","dependency_job_id":null,"html_url":"https://github.com/codeAbinash/scroll-observer","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeAbinash%2Fscroll-observer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeAbinash%2Fscroll-observer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeAbinash%2Fscroll-observer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeAbinash%2Fscroll-observer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/codeAbinash","download_url":"https://codeload.github.com/codeAbinash/scroll-observer/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240042829,"owners_count":19738961,"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":["javascript-library","scroll-observer","scrollview"],"created_at":"2024-11-08T19:14:50.144Z","updated_at":"2026-02-26T20:03:51.058Z","avatar_url":"https://github.com/codeAbinash.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Scroll Observer\n![Image](https://img.shields.io/github/size/codeabinash/scroll-observer/index.min.js)\n![Image](https://img.shields.io/github/license/codeabinash/scroll-observer)\n\n\u003cimg src=\"https://codeabinash.github.io/scroll-observer/images/logo.jpg\" width=\"100%\"\u003e\n\n# [Live Example](https://codeabinash.github.io/scroll-observer/example/)\n\n\n## Introduction\nScrollObserver A lightweight⚡(less than 1KB) JavaScript library to animate easily elements on scroll into view.\n## How it works\nWhen a DOM element is onscreen it adds `shown` class to it and when offscreen removes that `shown` class.\n## How to use\n```js\nscrollObserver('.card')\n```\n\nThe above JavaScript code adds and removes the `shown` class to the elements which have `card` class (select elements like `querySelectorAll()`) when they are onscreen and offscreen respectively.\n\n\nYou can pass multiple selectors as an array of string.\n```js\nscrollObserver(['.card', '.box'])\n```\n\n\n## CSS\nWrite css of `.card` and `.card.shown` like this\n```css\n.card{\n    ...\n    ...\n    transition: 400ms;\n    opacity : 0;\n}\n.card.shown {\n    opacity: 1;\n}\n```\n\n## Features\n### options argument\n```js\nconst options = {\n    root : document.querySelector('.container'),\n    rootMargin : '10px',\n    threshold: [0, 0.25, 0.5, 0.75, 1],\n    \n    once: true,\n    onshow: function (entry) {\n        console.log(\"Showing \")\n    },\n    \n    onhide: function (entry) {\n        console.log(\"Hiding \")\n    },\n}\n\nscrollObserver('.card', options)\n```\nRead more about Options argument from [MDN Docs ](https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API#creating_an_intersection_observer) \n\n## once\nIf the value of once is true, it will work once.\n\n## onshow and onhide\nThey are callback functions. They are called when the element becomes onscreen or offscreen\n\n## root, rootMargin, threshold\nRead them from [MDN Docs](https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API#creating_an_intersection_observer)\n\n\n\n\n\n\n\n## Example\n- index.html\n- style.css\n- script.js\n\n\n### index.html\n```html\n\u003c!DOCTYPE html\u003e\n\u003chtml lang=\"en\"\u003e\n\u003chead\u003e\n    \u003cmeta charset=\"UTF-8\"\u003e\n    \u003cmeta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\"\u003e\n    \u003cmeta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"\u003e\n    \u003ctitle\u003eScroll Observer\u003c/title\u003e\n    \u003cscript src=\"./script.js\" type=\"module\" defer\u003e\u003c/script\u003e\n    \u003clink rel=\"stylesheet\" href=\"style.css\"\u003e\n\u003c/head\u003e\n\n\u003cbody\u003e\n    \u003cdiv class=\"card\"\u003e\n        \u003ch1\u003eScroll Observer\u003c/h1\u003e\n    \u003c/div\u003e\n    \u003cdiv class=\"card\"\u003e\n        \u003ch1\u003eScroll Observer\u003c/h1\u003e\n    \u003c/div\u003e\n    \u003cdiv class=\"card\"\u003e\n        \u003ch1\u003eScroll Observer\u003c/h1\u003e\n    \u003c/div\u003e\n    \u003cdiv class=\"card\"\u003e\n        \u003ch1\u003eScroll Observer\u003c/h1\u003e\n    \u003c/div\u003e\n    \u003cdiv class=\"card\"\u003e\n        \u003ch1\u003eScroll Observer\u003c/h1\u003e\n    \u003c/div\u003e\n    \u003cdiv class=\"card\"\u003e\n        \u003ch1\u003eScroll Observer\u003c/h1\u003e\n    \u003c/div\u003e\n    \u003cdiv class=\"card\"\u003e\n        \u003ch1\u003eScroll Observer\u003c/h1\u003e\n    \u003c/div\u003e\n    \u003cdiv class=\"card\"\u003e\n        \u003ch1\u003eScroll Observer\u003c/h1\u003e\n    \u003c/div\u003e\n\u003c/body\u003e\n\u003c/html\u003e\n```\n\n\n### style.css\n```css\n*{\n    font-family: Arial, Helvetica, sans-serif;\n}\n.card{\n    width: min(90%, 500px);\n    aspect-ratio: 2 / 1;\n    margin-inline: auto;\n    background-color: hsl(61, 70%, 70%);\n    display: grid;\n    place-items: center;\n    margin-block: 7%;\n    border-radius: 10px;\n    transition: 400ms;\n    opacity: 0;\n    scale: 0.8;\n}\n.card.shown {\n    opacity: 1;\n    scale: 1;\n}\n```\n\n### script.js\n```js\nimport scrollObserver from 'https://codeabinash.github.io/scroll-observer/index.min.js'\nscrollObserver('.card')\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodeabinash%2Fscroll-observer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodeabinash%2Fscroll-observer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodeabinash%2Fscroll-observer/lists"}