Skip to content

Commit f6d42fb

Browse files
committed
add warn if does not support IntersectionObserver
1 parent f30fe78 commit f6d42fb

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

babel.config.js

+16
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
module.exports = {
22
comments: false,
3+
presets: [
4+
[
5+
"@babel/env",
6+
{
7+
targets: {
8+
ie: "10",
9+
edge: "17",
10+
firefox: "60",
11+
chrome: "67",
12+
safari: "11.1"
13+
},
14+
useBuiltIns: "usage",
15+
corejs: "3.6.5"
16+
}
17+
]
18+
],
319
plugins: ["transform-vue-jsx"],
420
/* presets: [["env", { modules: false }]], */
521
env: {

src/index.jsx

+17
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,22 @@ export default {
5555
this.observer.observe(this.$el);
5656
},
5757

58+
// is support IntersectionObserver
59+
isSupport() {
60+
if (
61+
!("IntersectionObserver" in window) ||
62+
!("IntersectionObserverEntry" in window) ||
63+
!(
64+
"intersectionRatio" in
65+
window.IntersectionObserverEntry.prototype
66+
)
67+
) {
68+
console.warn(
69+
"Your browser does not support IntersectionObserver!"
70+
);
71+
}
72+
},
73+
5874
// destroy observer
5975
destroyObserver() {
6076
if (this.observer) {
@@ -64,6 +80,7 @@ export default {
6480
}
6581
},
6682
mounted() {
83+
this.isSupport();
6784
this.createObserver();
6885
},
6986
beforeDestroy() {

0 commit comments

Comments
 (0)