{"id":42830370,"url":"https://github.com/wide/viewport","last_synced_at":"2026-01-30T11:26:56.343Z","repository":{"id":44094556,"uuid":"267885732","full_name":"wide/viewport","owner":"wide","description":"Handle intersection between elements and the viewport.","archived":false,"fork":false,"pushed_at":"2023-12-21T16:09:06.000Z","size":15,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-11-04T06:24:59.239Z","etag":null,"topics":["modulus"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/wide.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":"2020-05-29T15:01:14.000Z","updated_at":"2022-07-11T08:22:10.000Z","dependencies_parsed_at":"2022-09-26T17:01:33.170Z","dependency_job_id":null,"html_url":"https://github.com/wide/viewport","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/wide/viewport","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wide%2Fviewport","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wide%2Fviewport/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wide%2Fviewport/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wide%2Fviewport/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wide","download_url":"https://codeload.github.com/wide/viewport/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wide%2Fviewport/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28911821,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-30T08:15:08.179Z","status":"ssl_error","status_checked_at":"2026-01-30T08:14:31.507Z","response_time":66,"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":["modulus"],"created_at":"2026-01-30T11:26:55.724Z","updated_at":"2026-01-30T11:26:56.336Z","avatar_url":"https://github.com/wide.png","language":"JavaScript","readme":"# Viewport\r\n\r\nHandle intersection between elements and the viewport.\r\n\r\n\r\n## Install\r\n\r\n```\r\nnpm install @wide/viewport --save\r\n```\r\n\r\n\r\n## Usage\r\n\r\nObserve `[data-viewport]` elements:\r\n```js\r\nimport '@wide/viewport'\r\n```\r\n```html\r\n\u003cdiv data-viewport\u003e\u003c/div\u003e\r\n```\r\n\r\nThese elements will triggers 2 events when they appear in the viewport and when they leave :\r\n```js\r\n// use `e.detail` to get information about the scroll direction or the\r\n// appearance edge of the element (e.g: { edge: 'top', scroll: 'up' })\r\ndiv.addEventListener('viewport.enter', e =\u003e {})\r\ndiv.addEventListener('viewport.leave', e =\u003e {})\r\n```\r\n\r\nAside from these events, they will received 4 `css` classes:\r\n- `.viewport` on page loading, this is the default state\r\n- `.viewport-enter` when the element is entering the viewport\r\n- `.viewport-active` once the entering animation or transition is finished\r\n- `.viewport-leave` when the element has left the viewport\r\n\r\n### Custom CSS classes\r\n\r\nYou can replace the state class name with your own:\r\n```html\r\n\u003cdiv data-viewport=\"fade\"\u003e\u003c/div\u003e\r\n```\r\n\r\nThis element will now received these 4 `css` classes:\r\n- `.fade`\r\n- `.fade-enter`\r\n- `.fade-active`\r\n- `.fade-leave`\r\n\r\nExemple of an appearance transition:\r\n```html\r\n\u003cdiv class=\"foo\" data-viewport.once=\"fade\"\u003e\u003c/div\u003e\r\n```\r\n```scss\r\n.fade {\r\n  opacity: 0;\r\n  transform: translateY(80px);\r\n  transition: all 300ms;\r\n  \u0026-enter,\r\n  \u0026-active {\r\n    opacity: 1;\r\n    transform: translateY(0);\r\n  }\r\n}\r\n```\r\n\r\n### Observe once only\r\n\r\nYou can set an option to unlisten after entering the viewport once:\r\n```html\r\n\u003cdiv data-viewport.once\u003e\u003c/div\u003e\r\n```\r\n\r\n\r\n## Methods\r\n\r\nObserve programmaticaly an element in the viewport:\r\n```js\r\nimport viewport from '@wide/viewport'\r\n\r\nconst el = document.querySelector('.something')\r\nviewport(el, {\r\n  enter(el) {},\r\n  leave(el) {},\r\n  once: false,\r\n  name: 'fade'\r\n})\r\n```\r\n\r\n\r\n## Authors\r\n\r\n- **Aymeric Assier** - [github.com/myeti](https://github.com/myeti)\r\n- **Julien Martins Da Costa** - [github.com/jdacosta](https://github.com/jdacosta)\r\n\r\n\r\n## License\r\n\r\nThis project is licensed under the MIT License - see the [licence](licence) file for details","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwide%2Fviewport","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwide%2Fviewport","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwide%2Fviewport/lists"}