{"id":19326329,"url":"https://github.com/thisissoon/angular-inviewport","last_synced_at":"2025-04-10T03:55:50.263Z","repository":{"id":24003790,"uuid":"100366900","full_name":"thisissoon/angular-inviewport","owner":"thisissoon","description":"A simple lightweight library for Angular with no other dependencies that detects when an element is within the browser viewport and adds a \"sn-viewport-in\" or \"sn-viewport-out\" class to the element","archived":false,"fork":false,"pushed_at":"2023-07-13T18:22:55.000Z","size":3207,"stargazers_count":71,"open_issues_count":31,"forks_count":23,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-04-10T03:55:42.827Z","etag":null,"topics":["angular","directive","in-viewport","inviewport","ngx","ngx-in-viewport","ngx-inviewport","ngx-library","resize","scrolling","viewport"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/thisissoon.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","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":"2017-08-15T10:31:49.000Z","updated_at":"2025-01-17T21:13:37.000Z","dependencies_parsed_at":"2024-06-18T15:39:30.288Z","dependency_job_id":null,"html_url":"https://github.com/thisissoon/angular-inviewport","commit_stats":null,"previous_names":[],"tags_count":33,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thisissoon%2Fangular-inviewport","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thisissoon%2Fangular-inviewport/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thisissoon%2Fangular-inviewport/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thisissoon%2Fangular-inviewport/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thisissoon","download_url":"https://codeload.github.com/thisissoon/angular-inviewport/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248155001,"owners_count":21056542,"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":["angular","directive","in-viewport","inviewport","ngx","ngx-in-viewport","ngx-inviewport","ngx-library","resize","scrolling","viewport"],"created_at":"2024-11-10T02:13:05.871Z","updated_at":"2025-04-10T03:55:50.245Z","avatar_url":"https://github.com/thisissoon.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Angular InViewport\n\n[![CircleCI][circle-badge]][circle-badge-url]\n[![Coverage Status][coveralls-badge]][coveralls-badge-url]\n[![Commitizen friendly][commitizen-badge]][commitizen]\n\nA simple lightweight library for [Angular][angular] that detects when an element is within the browser viewport and adds a `sn-viewport--in` or `sn-viewport--out` class to the element.\n\nThis is a simple library for [Angular][angular], implemented in the [Angular Package Format v5.0][apfv5].\n\n## Install\n\n### via NPM\n\n```bash\nnpm i @thisissoon/angular-inviewport\n```\n\n### via Yarn\n\n```bash\nyarn add @thisissoon/angular-inviewport\n```\n\n`app.module.ts`\n\n```ts\nimport { InViewportModule } from '@thisissoon/angular-inviewport';\n\n@NgModule({\n  imports: [InViewportModule]\n})\nexport class AppModule {}\n```\n\n`app.server.module.ts`\nOnly required For Server Side Rendering\n\n```ts\nimport { InViewportModule } from '@thisissoon/angular-inviewport';\n\n@NgModule({\n  imports: [InViewportModule.forServer()]\n})\nexport class AppServerModule {}\n```\n\n## Browser Support\n\nThis library makes use of the [Intersection Observer API][intersection-observer-api] which requires a [polyfill][intersection-observer-polyfill] to work on some browsers.\n\n### Install the polyfill\n\n```bash\nnpm i intersection-observer\n```\n\nOr use yarn\n\n```bash\nyarn add intersection-observer\n```\n\n### Include the polyfill\n\nAdd this somewhere in your `src/polyfills.ts` file\n\n```ts\nimport 'intersection-observer';\n```\n\n## Examples\n\nA working example can be found [here](https://github.com/thisissoon/angular-inviewport/tree/master/src).\n\n### Just using classes\n\n#### `app.component.html`\n\n```html\n\u003cp class=\"foo\" snInViewport\u003eAmet tempor excepteur occaecat nulla.\u003c/p\u003e\n```\n\n#### `app.component.css`\n\n```css\n.foo {\n  transition: transform 0.35s ease-out;\n}\n\n.foo.sn-viewport--out {\n  transform: translateY(-30px);\n}\n\n.foo.sn-viewport--in {\n  transform: translateY(0);\n}\n```\n\n### Using events\n\n#### `app.component.html`\n\n```html\n\u003cp\n  class=\"foo\"\n  [ngClass]=\"{highlight: highlight}\"\n  snInViewport\n  (inViewportChange)=\"onInViewportChange($event)\"\u003e\n  Amet tempor excepteur occaecat nulla.\n\u003c/p\u003e\n```\n\n#### `app.component.ts`\n\n```ts\nexport class AppComponent {\n  highlight = false;\n\n  onInViewportChange(inViewport: boolean) {\n    this.highlight = inViewport;\n  }\n}\n```\n\n#### `app.component.css`\n\n```css\n.highlight {\n  background-color: yellow;\n}\n```\n\n### Debounce example\n\n#### `app.component.html`\n\n```html\n\u003cp\n  class=\"foo\"\n  snInViewport\n  (inViewportChange)=\"onInViewportChange($event)\"\u003e\n  Amet tempor excepteur occaecat nulla.\n\u003c/p\u003e\n```\n\n#### `app.component.ts`\n\n```ts\nimport { Subject } from 'rxjs';\nimport { debounceTime } from 'rxjs/operators';\n\nexport class AppComponent {\n  inViewportChange: Subject\u003cboolean\u003e;\n\n  constructor() {\n    this.inViewportChange = new Subject\u003cboolean\u003e().pipe(debounceTime(300));\n\n    this.inViewportChange.subscribe((inViewport: boolean) =\u003e\n      console.log(`element is in viewport: ${inViewport}`)\n    );\n  }\n\n  onInViewportChange(inViewport: boolean) {\n    this.inViewportChange.next(inViewport);\n  }\n}\n```\n\n### Offset example\n\nYou can pass any options [Intersection Observer][intersection-observer-api] accepts using the `[inViewportOptions]` property. This allows offsets to be set using the `rootMargin` property. This property works the same as `margin` property in CSS.\n\n#### `app.component.html`\n\n```html\n\u003cp\n  class=\"foo\"\n  snInViewport\n  [inViewportOptions]=\"{\n    rootMargin: '100px 0px 0px 0px'\n  }\"\u003e\n  Amet tempor excepteur occaecat nulla.\n\u003c/p\u003e\n```\n\n### Limit example\n\n#### `app.component.html`\n\n```html\n\u003cp\n  class=\"foo\"\n  [ngClass]=\"{highlight: highlight}\"\n  snInViewport\n  (inViewportChange)=\"onInViewportChange($event)\"\u003e\n  Amet tempor excepteur occaecat nulla.\n\u003c/p\u003e\n```\n\n#### `app.component.ts`\n\n```ts\nimport { Subject } from 'rxjs';\nimport { take } from 'rxjs/operators';\n\nexport class AppComponent {\n  inViewportChange = new Subject;\n  highlight = false;\n\n  constructor() {\n    this.inViewportChange = new Subject\u003cboolean\u003e().pipe(take(5));\n\n    this.inViewportChange.subscribe((inViewport: boolean) =\u003e\n      this.highlight = inViewport;\n    );\n  }\n\n  onInViewportChange(inViewport: boolean) {\n    this.inViewportChange.next(inViewport);\n  }\n}\n```\n\n#### `app.component.css`\n\n```css\n.highlight {\n  background-color: yellow;\n}\n```\n\n## Development server\n\nRun `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files.\n\n## Code scaffolding\n\nRun `ng generate component component-name` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module`.\n\n## Build\n\nRun `ng build` to build the project. The build artifacts will be stored in the `dist/` directory. Use the `-prod` flag for a production build.\n\n## Server side rendering\n\nThe app can be rendered on a server before serving pages to the client. Server side rendering is achieved using [Express](https://expressjs.com/) and [Angular Universal](https://github.com/angular/universal) with [Express](https://expressjs.com/) running a [node](https://nodejs.org/en/) web server and [@nguniversal/express-engine](https://github.com/angular/universal/tree/master/modules/express-engine) providing a template engine for [Express](https://expressjs.com/) to render the angular pages.\n\nRun `npm run build:ssr \u0026\u0026 npm run serve:ssr` to build client and server bundles and run an express app which will render the angular templates before being sent to the client. Navigate to `http://localhost:4000/` to view the SSR version of the app.\n\n## Running unit tests\n\nRun `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io).\n\n## Running end-to-end tests\n\nRun `ng e2e` to execute the end-to-end tests via [Protractor](http://www.protractortest.org/).\n\n## Making Commits\n\nThis repo uses [Commitizen CLI][commitizen] and [Conventional Changelog][conventional-changelog] to create commits and generate changelogs. Instead of running `git commit` run `git cz` and follow the prompts. Changelogs will then be generated when creating new releases by running `npm run release`.\n\n## Making Releases\n\nRun `npm run release` to create a new release. This will use [Standard Version][standard-version] to create a new release. [Standard Version][standard-version] will generate / update the changelog based on commits generated using [Commitizen CLI][commitizen], update the version number following semantic versioning rules and then commit and tag the commit for the release. Simply run `git push --follow-tags origin master`.\n\n## Further help\n\nTo get more help on the Angular CLI use `ng help` or go check out the [Angular CLI README](https://github.com/angular/angular-cli/blob/master/README.md).\n\n[circle-badge]: https://circleci.com/gh/thisissoon/angular-inviewport.svg?style=shield\n[circle-badge-url]: https://circleci.com/gh/thisissoon/angular-inviewport\n[coveralls-badge]: https://coveralls.io/repos/github/thisissoon/angular-inviewport/badge.svg?branch=master\n[coveralls-badge-url]: https://coveralls.io/github/thisissoon/angular-inviewport?branch=master\n[angular]: https://angular.io/\n[commitizen]: http://commitizen.github.io/cz-cli/\n[commitizen-badge]: https://img.shields.io/badge/commitizen-friendly-brightgreen.svg\n[conventional-changelog]: https://github.com/conventional-changelog/conventional-changelog\n[standard-version]: https://github.com/conventional-changelog/standard-version\n[apfv5]: https://docs.google.com/document/d/1CZC2rcpxffTDfRDs6p1cfbmKNLA6x5O-NtkJglDaBVs/edit#heading=h.k0mh3o8u5hx\n[intersection-observer-api]: https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API\n[intersection-observer-polyfill]: https://github.com/w3c/IntersectionObserver/tree/master/polyfill\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthisissoon%2Fangular-inviewport","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthisissoon%2Fangular-inviewport","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthisissoon%2Fangular-inviewport/lists"}