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
This used to be a [ponyfill](https://ponyfill.com) for
12
12
`Element.scrollIntoViewIfNeeded`. Since then the CSS working group have decided to implement its features in `Element.scrollIntoView` as the option `scrollMode: "if-needed"`. Thus this library got rewritten to implement that spec instead of the soon to be deprecated one.
What does ponyfilling smooth scrolling mean, and why is it implemented in [`smooth-scroll-into-view-if-needed`](https://github.com/scroll-into-view/smooth-scroll-into-view-if-needed) instead?
63
97
The answer is bundlesize. If this package adds smooth scrolling to browsers that's missing it then the overall bundlesize increases regardless of wether you use this feature or not.
That's why only native smooth scrolling is supported out of the box. There are two common ways you can smooth scroll browsers that don't support it natively. Below is all three, which one is best for you depends on what is the most important to your use case:: load time, consistency or quality.
77
111
78
-
#####Load time
112
+
### Load time
79
113
80
114
In many scenarios smooth scrolling can be used as a progressive enhancement. If the user is on a browser that don't implement smooth scrolling it'll simply scroll instantly and your bundlesize is only as large as it has to be.
81
115
@@ -85,7 +119,7 @@ import scrollIntoView from 'scroll-into-view-if-needed'
85
119
scrollIntoView(node, { behavior:'smooth' })
86
120
```
87
121
88
-
#####Consistency
122
+
### Consistency
89
123
90
124
If a consistent smooth scrolling experience is a priority and you really don't want any surprises between different browsers and enviroments. In other words don't want to be affected by how a vendor might implement native smooth scrolling, then [`smooth-scroll-into-view-if-needed`](https://github.com/scroll-into-view/smooth-scroll-into-view-if-needed) is your best option. It ensures the same smooth scrolling experience for every browser.
91
125
@@ -95,7 +129,7 @@ import smoothScrollIntoView from 'smooth-scroll-into-view-if-needed'
95
129
smoothScrollIntoView(node, { behavior:'smooth' })
96
130
```
97
131
98
-
#####Quality
132
+
### Quality
99
133
100
134
If you want to use native smooth scrolling when it's available, and fallback to the smooth scrolling ponyfill:
The auto option unlocks a few interesting opportunities.
133
167
The browser will decide based on user preferences wether it should smooth scroll or not.
@@ -153,11 +187,11 @@ html,
153
187
}
154
188
```
155
189
156
-
#####`'smooth'`
190
+
#### `'smooth'`
157
191
158
192
Using `behavior: 'smooth'` is the easiest way to smooth scroll an element as it does not require any CSS, just a browser that implements it. [More information.](#ponyfill-smooth-scrolling)
159
193
160
-
#####`Function`
194
+
#### `Function`
161
195
162
196
When given a function then this library will only calculate what should be scrolled and leave it up to you to perform the actual scrolling.
163
197
@@ -189,39 +223,39 @@ Check the demo to see an [example with popmotion and a spring transition](https:
189
223
190
224
> If you only need the custom behavior you might be better off by using the compute library directly: https://github.com/scroll-into-view/compute-scroll-into-view
The old `Element.scrollIntoView` api only had two settings, align to top or bottom. [`Element.scrollIntoViewIfNeeded`](https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoViewIfNeeded) had two more, align to the center or nearest edge.
308
342
The `Element.scrollIntoView` spec now supports these two modes as `block: 'center'` and `block: 'nearest'`.
309
343
Breaking changes sucks, but on the plus side your code is now more portable and will make this library easier to delete from your codebase on the glorious day browser support is good enough.
@@ -352,11 +386,11 @@ import scrollIntoView from 'smooth-scroll-into-view-if-needed'
352
386
scrollIntoView(target, { behavior:'smooth' })
353
387
```
354
388
355
-
####easing
389
+
## easing
356
390
357
391
This feature is removed, but you can achieve the same thing by implementing [`behavior: Function`](#function).
358
392
359
-
####handleScroll
393
+
## handleScroll
360
394
361
395
This is replaced with [`behavior: Function`](#function) with one key difference. Instead of firing once per element that should be scrolled, the new API only fire once and instead give you an array so you can much easier batch and scroll multiple elements at the same time. Or sync scrolling with another element if that's the kind of stuff you're into, I don't judge.
362
396
@@ -374,12 +408,12 @@ This is replaced with [`behavior: Function`](#function) with one key difference.
374
408
+})})
375
409
```
376
410
377
-
####offset
411
+
## offset
378
412
379
413
This was always a buggy feature and warned against using in v1 as it might get dropped.
380
414
It's much safer to use CSS wrapper elements for this kind of thing.
0 commit comments