参考错误:找不到变量:IntersectionObserver [英] Reference error: Can't find variable: IntersectionObserver

查看:121
本文介绍了参考错误:找不到变量:IntersectionObserver的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在ios 13上运行的cordova 8.0.0应用程序中使用IntersectionObserver.当我通过野生动物园检查我的应用程序时,看到初始化错误:

I'm trying to use IntersectionObserver in cordova 8.0.0 app which is running on ios 13. When I inspect my app via safari, I see an error on intialization:

ReferenceError:找不到变量:IntersectionObserver

这表明IntersectionObserver不可用,我应该使用polyfill.但!我读过很多帖子,声称iOS Safari 12+完全支持IntersectionObserver.我有点假设,cordova将运行在天生可用的WKWebView上,因此它应该在没有polyfill的情况下也可以工作,对吗?

This would suggest, that IntersectionObserver is not available, and I should use a polyfill. But! I've read many post claiming that IntersectionObserver is nativly supported in iOS safari 12+. And I kinda assume, that cordova would be running nativly available WKWebView, so it should work without polyfill, right?

我发现我的野生动物园实验功能中启用了IntersectionObserver,所以也许还有一个选项/标志可以用来强制在我的应用程序中启用此功能?如果可能的话,我真的想避免使用polyfill.

I've found that I've got IntersectionObserver enabled in my safari experimental features, so maybe there is an option/flag I could use to force enable this feature in my app as well? I'd really like to avoid using polyfill if it's possible..

感谢任何建议

推荐答案

IntersectionObserver API.但是它是通过实验功能"支持的,并且默认情况下启用.我假设默认情况下在cordova中未启用实验性功能,但到目前为止,我还没有找到一种将其配置为启用的方法.

IntersectionObserver API is supported on iOS safari since 12.2. Yet it was supported via 'experimental feature' and enabled by default. I assume that experimental features are not enabled under cordova by default, so far I haven't found a way to configure it to be enabled.

一种选择是使用polyfill: https://www.npmjs.com/package/交集观察者.我对自己进行了测试,性能还不够好,它使用 setTimeout MutationObserver 来观察启用了所有选项的整个文档.

An option is to use polyfill: https://www.npmjs.com/package/intersection-observer. I tested myself and performance is not good enough, it uses either setTimeout or MutationObserver to observe whole document with all options enabled.

这篇关于参考错误:找不到变量:IntersectionObserver的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆