Created
September 1, 2019 13:02
-
-
Save BrockReece/5696cbc411fcbfa6b12d163b20974282 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { onMounted, onUnmounted, ref } from "@vue/composition-api"; | |
export function useOnScreen() { | |
let isOnScreen = ref(false); | |
const observer = new IntersectionObserver(entries => { | |
isOnScreen.value = entries.some(entry => entry.intersectionRatio > 0); | |
}); | |
onMounted(function() { | |
observer.observe(this.$el); | |
}); | |
onUnmounted(function(vm) { | |
observer.unobserve(this.$el); | |
}); | |
return { | |
isOnScreen, | |
observer | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment