magic-akari / seamless-scroll-polyfill

Scroll Behavior polyfill
https://www.npmjs.com/package/seamless-scroll-polyfill
MIT License
159 stars 11 forks source link

Add IE11 support #94

Closed Dan503 closed 4 years ago

Dan503 commented 4 years ago

IE11 fix: Swapping Element prototype with HTMLElement

For some reason, IE11 doesn't respond to prototype modifications done to the Element prototype.

However it does respond to changes to the HTMLElement prototype.

IE11 fix: Adding supportsScrollBehavior check to elem.scrollIntoView() getOriginalFunc function

IE11 has partial support for element.scrollIntoView().

Since IE11 recognizes that the scrollIntoView function on elements exists, it skips applying the polyfill and uses native code instead.

This change ensures that the browser will only use native code under two conditions:

  1. It must recognize the function name.
  2. It must support "scrollBehavior" functionality.

If either of those conditions are false, it will use the polyfill instead.

mkScript commented 4 years ago

Hi @Dan503,

I'm facing similar problems when using the polyfill with MS Edge 18. Have you checked if your fix could also help here? It is probably the same problem.

Dan503 commented 4 years ago

@mkScript I haven't checked MS Edge 18 but I wouldn't be surprised if it has the same problems as IE since IE11 is just the grandfather of MS Edge.

Dan503 commented 4 years ago

@mkScript if you want to get the fix right now without waiting, copy the node_modules/seamless-scroll-polyfill/dist/esm folder into your project source folder and save the files into git. Delete all the .map files, you don't need them. (I'm assuming your project is using ES6 imports or Typescript).

Make the changes outlined in this PR manually, then when importing seamless-scroll-polyfill, import from your version in the source folder rather than from node_modules.

magic-akari commented 4 years ago

sorry for the late reply.

What about polyfill the HTMLElement, SVGElement, and Element at the same time?

Dan503 commented 4 years ago

Ok, I can make that change. It will probably mean making a helper function to apply to all 3 every time rather than repeating code every time.

Dan503 commented 4 years ago

I've modified all three now.

In Element.scroll.ts I'm still only checking HTMLElement.prototype since it is checking for existence rather than modifying the prototype. Checking for only HTMLElement.prototype should be fine I think.

magic-akari commented 4 years ago

LGTM

Dan503 commented 4 years ago

Thanks for merging 😊

Don't forget to publish a new version to npm though.