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
{{ message }}
This repository was archived by the owner on Jan 30, 2024. It is now read-only.
To accomplish the desired behavior you need to take in account the following:
34
-
- You need to have a scroll container
35
-
- Inside the scroll container you need:
36
-
- The sticky element
37
-
- An element that when the sticky element bypass it, the directive will trigger the custom class. We call this _triggerOn_ element
38
-
- The _triggerOn_ element **must** be relative positioned (has this css property `position: relative`)
39
-
-> _We decided that you control this, because adding `position: relative` to an element can change the visual aspect to something not desired and you will asking why and blaming yourself for something that you are not conscious of, so following the [Single Responsibility Principle](https://en.wikipedia.org/wiki/Single_responsibility_principle) this directive will not take care of that_
34
+
35
+
- You need to have a scroll container
36
+
- Inside the scroll container you need:
37
+
- The sticky element
38
+
- An element that when the sticky element bypass it, the directive will trigger the custom class. We call this _triggerOn_ element
39
+
- The _triggerOn_ element **must** be relative positioned (has this css property `position: relative`)
40
+
-> _We decided that you control this, because adding `position: relative` to an element can change the visual aspect to something not desired and you will asking why and blaming yourself for something that you are not conscious of, so following the [Single Responsibility Principle](https://en.wikipedia.org/wiki/Single_responsibility_principle) this directive will not take care of that_
40
41
41
42
`dummy.component.scss`
43
+
42
44
```scss
43
45
.scroll-container {
44
46
border: #cccccc1pxsolid;
@@ -48,7 +50,7 @@ To accomplish the desired behavior you need to take in account the following:
48
50
}
49
51
50
52
.title {
51
-
background-color: #1C5089;
53
+
background-color: #1c5089;
52
54
color: #ffffff;
53
55
font-size: 32px;
54
56
font-weight: bold;
@@ -61,18 +63,20 @@ To accomplish the desired behavior you need to take in account the following:
@@ -84,101 +88,108 @@ To accomplish the desired behavior you need to take in account the following:
84
88
</div>
85
89
```
86
90
91
+
### Note
92
+
93
+
If you're using angular version >= 9 and providing the `triggerOn` value as a string, you need to do it this way `[triggerOn]="'text-content'"` because Ivy changed something about how we pass parameters. There is an [issue](https://github.com/angular/angular/issues/34227) open about it
94
+
95
+
According to [Ivy Compatibility guide](https://angular.io/guide/ivy-compatibility)
96
+
97
+
> Unbound inputs for directives (e.g. name in <my-compname="">) are now set upon creation of the view, before change detection runs (previously, all inputs were set during change detection).
| `@Input() scrollContainer: string | ElementRef | HTMLElement` | Top container of the sticky element that has the scroll. _If an string is provided, it must be the ID of the element._|
175
-
| `@Input() triggerOn: string | ElementRef | HTMLElement` | When the sticky element bypass this element the custom class will apply. _If an string is provided, it must be the ID of the element._|
176
-
|`@Input() debugMode: boolean`| Display or hide the sentinel element. |
177
-
|`@Input() classWhenSticky: string`| CSS class to be added to the target element when becomes sticky. |
178
-
|`@Input() zIndex: number = 10`| CSS `zIndex` value to set to the target element. By default is 10. |
179
-
|`@Input() top: number = 0`| CSS `top` value to set to the sticky element. By default is 0. |
| `@Input() scrollContainer: string | ElementRef | HTMLElement` | Top container of the sticky element that has the scroll. _If an string is provided, it must be the ID of the element._|
186
+
| `@Input() triggerOn: string | ElementRef | HTMLElement` | When the sticky element bypass this element the custom class will apply. _If an string is provided, it must be the ID of the element._|
187
+
|`@Input() debugMode: boolean`| Display or hide the sentinel element.|
188
+
|`@Input() classWhenSticky: string`| CSS class to be added to the target element when becomes sticky.|
189
+
|`@Input() zIndex: number = 10`| CSS `zIndex` value to set to the target element. By default is 10.|
190
+
|`@Input() top: number = 0`| CSS `top` value to set to the sticky element. By default is 0.|
180
191
181
-
## Why?
192
+
## Why
182
193
183
194
Adding a custom class when an element becomes sticky is the objective of this directive. This is achieved by using [Intersection Observer](https://developer.mozilla.org/docs/Web/API/Intersection_Observer_API) and avoid using scroll events to keep a good performance.
184
195
@@ -193,10 +204,10 @@ The intention of this directive is to implement the article [An event for CSS po
193
204
> The Intersection Observer API is highly [supported](https://caniuse.com/#feat=intersectionobserver) across the different browsers, however if you have a target audience that is not currently being supported you can use the [Intersection Observer Polyfill](https://github.com/w3c/IntersectionObserver/tree/master/polyfill)
194
205
195
206
### References
207
+
196
208
-[An event for CSS position:sticky](https://developers.google.com/web/updates/2017/09/sticky-headers)
0 commit comments