You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
perf(InViewport): use intersection observer to calculate inviewport state (#25)
Replace custom logic to calculate `InViewport` status for native `IntersectionObserver` API to improve performance and clean up code
BREAKING CHANGE: Removed `forRoot` method in module which is no longer required for `AppBrowserModule`. Replaced with `forServer` method for `AppServerModule`. Removed debounce feature and rxjs dependancy to leave implementation up to the consumer of the library. This reduces bundle size if debounce feature is not being used. Updated inviewport classes to `sn-inviewport--in` and `sn-inviewport--out` to match SOON styleguide
This project was generated with[Angular CLI](https://github.com/angular/angular-cli) version 1.5.4.
7
+
A 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.
8
8
9
-
A 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.
10
-
11
-
This is a simple library for [Angular][angular], implemented in the [Angular Package Format v5.0](https://docs.google.com/document/d/1CZC2rcpxffTDfRDs6p1cfbmKNLA6x5O-NtkJglDaBVs/edit#heading=h.k0mh3o8u5hx).
9
+
This is a simple library for [Angular][angular], implemented in the [Angular Package Format v5.0][apfv5].
This library makes use of the [Intersection Observer API][intersection-observer-api] which requires a [polyfill][intersection-observer-polyfill] to work on some browsers.
51
+
52
+
### Install the polyfill
53
+
54
+
```bash
55
+
npm i intersection-observer
56
+
```
57
+
58
+
Or use yarn
59
+
60
+
```bash
61
+
yarn add intersection-observer
62
+
```
63
+
64
+
### Include the polyfill
65
+
66
+
Add this somewhere in your `src/polyfills.ts` file
67
+
68
+
```ts
69
+
import'intersection-observer';
70
+
```
71
+
58
72
## Examples
59
73
74
+
A working example can be found [here](https://github.com/thisissoon/angular-inviewport/tree/master/src) folder.
75
+
60
76
### Just using classes
61
77
62
78
#### `app.component.html`
@@ -72,11 +88,11 @@ export class AppServerModule {}
72
88
transition: transform 0.35sease-out;
73
89
}
74
90
75
-
.foo.sn-viewport-out {
91
+
.foo.sn-viewport--out {
76
92
transform: translateY(-30px);
77
93
}
78
94
79
-
.foo.sn-viewport-in {
95
+
.foo.sn-viewport--in {
80
96
transform: translateY(0);
81
97
}
82
98
```
@@ -86,7 +102,10 @@ export class AppServerModule {}
Window scroll and resize events doesn't cover all potential use cases for the inViewport status check. For example if using directive inside a carousel. To trigger a check manually simply assign a template variable value to the directive and call `calculateInViewportStatus` when you require.
@@ -161,6 +178,12 @@ Run `ng generate component component-name` to generate a new component. You can
161
178
162
179
Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory. Use the `-prod` flag for a production build.
163
180
181
+
## Server side rendering
182
+
183
+
The 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.
184
+
185
+
Run `npm run build:ssr && 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.
186
+
164
187
## Running unit tests
165
188
166
189
Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io).
@@ -190,3 +213,6 @@ To get more help on the Angular CLI use `ng help` or go check out the [Angular C
0 commit comments