Skip to content

Commit

Permalink
feat: open paywall after user idle for 1s
Browse files Browse the repository at this point in the history
  • Loading branch information
DanSnow committed Feb 1, 2024
1 parent c613e21 commit 2e0268a
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/components/LeakyPaywall.vue
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,23 @@ useEventListener(window, 'wheel', (event) => {
}
})
// If user scroll over 40%, open the paywall
const { idle } = useIdle(1000, {
events: ['mousedown', 'resize', 'keydown', 'wheel'],
})
const everIdle = ref(false)
// Detect whenever user idle over 1s
whenever(idle, () => {
everIdle.value = true
})
// If user scroll over 40%, we will need paywall
const isNeedPaywall = computed(() => y.value > height.value * 0.4)
whenever(
() => y.value > height.value * 0.4,
// Only if user idle, and over 40% will open paywall
logicAnd(everIdle, isNeedPaywall),
async () => {
scrollLock.value = true
show.value = true
Expand Down

0 comments on commit 2e0268a

Please sign in to comment.