{"id":21937750,"url":"https://github.com/jaspero/ng-image-preload","last_synced_at":"2025-07-01T11:33:05.791Z","repository":{"id":23872280,"uuid":"100062949","full_name":"Jaspero/ng-image-preload","owner":"Jaspero","description":"An image preload module for Angular using IntersectionObserver in favour of scroll listener's.","archived":false,"fork":false,"pushed_at":"2022-08-19T17:05:36.000Z","size":16839,"stargazers_count":8,"open_issues_count":2,"forks_count":1,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-03-18T19:51:06.819Z","etag":null,"topics":["angular","image-preloader","intersectionobserver","lazy-loading"],"latest_commit_sha":null,"homepage":"https://jaspero.github.io/ng-image-preload/","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/Jaspero.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":["Jaspero"]}},"created_at":"2017-08-11T19:09:30.000Z","updated_at":"2022-02-14T12:02:26.000Z","dependencies_parsed_at":"2022-07-25T13:45:07.958Z","dependency_job_id":null,"html_url":"https://github.com/Jaspero/ng-image-preload","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jaspero%2Fng-image-preload","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jaspero%2Fng-image-preload/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jaspero%2Fng-image-preload/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jaspero%2Fng-image-preload/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Jaspero","download_url":"https://codeload.github.com/Jaspero/ng-image-preload/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227018516,"owners_count":17717932,"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","image-preloader","intersectionobserver","lazy-loading"],"created_at":"2024-11-29T01:25:23.605Z","updated_at":"2024-11-29T01:25:24.381Z","avatar_url":"https://github.com/Jaspero.png","language":"TypeScript","funding_links":["https://github.com/sponsors/Jaspero"],"categories":[],"sub_categories":[],"readme":"[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)\n[![CircleCI](https://circleci.com/gh/Jaspero/ng-image-preload/tree/master.svg?style=svg)](https://circleci.com/gh/Jaspero/ng-image/preload/tree/master)\n[![NPM Version](https://img.shields.io/npm/v/@jaspero/ng-image-preload.svg)](https://www.npmjs.com/package/@jaspero/ng-image-preload)\n\n# NG Image Preload\n\nAn image preload module for Angular using [IntersectionObserver](https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API) in favour of scroll listener's.\n\n```\nnpm install --save @jaspero/ng-image-preload\n```\n\n## Example\n\nA demo can be found here:\n\nhttps://jaspero.github.io/ng-image-preload/\n\n## Setup\n\nImport `JpImagePreloaderModule` in your `@NgModule`:\n\n```ts\n@NgModule({\n    imports: [\n        JpImagePreloaderModule.forRoot()\n    ],\n    declarations: [AppComponent],\n    bootstrap: [AppComponent]\n})\nexport class AppModule {}\n```\n\nThen in your component initialize the service:\n\n```ts\nclass AppComponent implements OnInit {\n  constructor(private preload: JpPreloadService) {}\n\n  ngOnInit() {\n    this.preload.initialize();\n  }\n}\n```\n\nThe `initialize` method accepts an optional `options` object:\n\n### Options\n\n| Name       | Type   | Default |\n| ---------- | ------ | ------- |\n| rootMargin | string | 0 50px  |\n| threshold  | number | 0.1     |\n\nA description for this options can be found [here](https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API).\n\n## How To Use\n\nThere are two ways to consume the library. Using the service or the directive.\n\n### Service\n\nInject the `PreloadService` in to a component.\n\n```ts\nconstructor(\n    private preload: PreloadService\n) {}\n\n// Then add an image element to the que like this:\naddImage(element: HTMLElement, config: ElementConfig) {\n    this.preload.addImage(element, config);\n}\n```\n\n### Directive\n\nYou can add the `jpPreload` directive to an `img` element like this:\n\n```html\n\u003cimg src=\"initialImage.jpg\" jpPreload=\"someImage.jpg\"\u003e\u003c/img\u003e\n```\n\nThe `initialImage.jpg` will not be preloaded, this is usually a spinner or some other light image.\nThe `someImage.jpg` image will be shown when the element is in view.\n\nIf you need to preload a background image the `jpPreload` directive can be placed on any html element like this:\n\n```html\n\u003cdiv class=\"some-element\" jpPreload=\"someImage.jpg\"\u003e\u003c/div\u003e\n```\n\nTo show an image initially you can add a css background-image to the class. This image will then be replaced when the element is in view.\n\nYou can also attach a fallback (loads if the requested image fails) like this:\n\n```html\n\u003cimg\n  src=\"initialImage.jpg\"\n  jpPreload=\"someImage.jpg\"\n  fallback=\"someFallback.jpg\"\n/\u003e\n```\n\n## License\n\nMIT © [Jaspero co.](mailto:info@jaspero.co)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjaspero%2Fng-image-preload","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjaspero%2Fng-image-preload","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjaspero%2Fng-image-preload/lists"}