Skip to content

pass on extra arguments to scrollTo to enable smooth scrolling with behaviour #2069

@BorjaRafols

Description

@BorjaRafols

What problem does this feature solve?

Smooth scrolling to same page anchor tags.

Right now smooth scrolling can only work by custom implementations, but the new Firefox spec contemplates a scrollBehaviour css property which can be polyfilled in older browsers.

Vue-router should take advantage of this new property

What does the proposed API look like?

Basically, the object returned from the scrollBehavior function should have some more parameters and change the current x, y positions into named parameters.

This is an example of the future object to be returned.

{
top: 2500, // this is the x value
left: 0, // this is the y value
behavior: 'smooth' //
};

This is getting implemented in most current browsers, couldn't find the spec thought. If anybody finds it please sahre the link.

Anyway, there is this beatyfull polyfill: https://www.npmjs.com/package/smoothscroll-polyfill

which adds this scrollTo({}) behaviour to old browsers.

I haven't dig much into the vue-router code. But it looks to me as if the only change needed is this file:
https://github.com/vuejs/vue-router/blob/dev/src/util/scroll.js

Maybe we could add some conditions on line 126 to return the current implementation or translate the old object:

{ x, y } to

{ top: x, left: y, behaviour: x }

Sorry if markup sucks, I'll do some more work if this gets atention

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions