Skip to content

Commit

Permalink
fx: restart prompt & vid replacement (#27)
Browse files Browse the repository at this point in the history
* fx: callback isFixed issue

* fx: autoplay in batterysaver mode

* up: vue

* msc: ipx routes not working

* fx: prerendering issue

* fx: nuxt image route detection (prerender)

* fx: contact btn scaling issue
  • Loading branch information
whatphilipcodes authored Apr 29, 2024
1 parent 2d106f9 commit 7e29e89
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 178 deletions.
File renamed without changes.
22 changes: 14 additions & 8 deletions components/Rotor/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const blocker = new BlockExceptionHandler('rotor-component')
let pendingAlign: NodeJS.Timeout | null = null
//
onBeforeUnmount(() => {
onUnmounted(() => {
exit()
})
Expand All @@ -49,8 +49,6 @@ function enter(alignDelay = 800) {
if (pendingAlign) clearTimeout(pendingAlign)
pendingAlign = setTimeout(() => {
alignSwiper()
window.addEventListener('touchend', alignSwiper, { passive: false })
window.addEventListener('wheel', alignSwiper, { passive: false })
pendingAlign = null
}, alignDelay) // delay to prevent scroll jump on scroll stop
Expand All @@ -59,29 +57,37 @@ function enter(alignDelay = 800) {
defineExpose({ enter })
function exit() {
if (pendingAlign) clearTimeout(pendingAlign)
pendingAlign = null
exitScrollToCb()
isFixed.value = false
blocker.detachEvent('wheel', window)
blocker.detachEvent('touchstart', window)
rotorWrap.value?.classList.remove('block-touch-actions')
window.removeEventListener('touchend', alignSwiper)
window.removeEventListener('wheel', alignSwiper)
isFixed.value = false
props.exitCallback?.()
}
//
const { scrollToCb } = useScrollCallback()
const { scrollToCb, exitScrollToCb } = useScrollCallback()
const rotorBottom = computed(() => {
if (!rotorWrap.value) return 0
return rotorWrap.value?.offsetTop + rotorWrap.value?.offsetHeight
})
function alignSwiper() {
scrollToCb(rotorBottom.value - window.innerHeight, () => {
isFixed.value = true
// console.log('log, scrollToCb -> callback', 'isFixed:', isFixed.value)
})
}
//
// watchImmediate(isFixed, (val) => {
// console.log('log, isFixed:', val)
// })
//
store.addSegmentCallback('getRotorButtons', () => {
if (store.activeSegment.buttons?.length == 0) return
Expand Down
27 changes: 20 additions & 7 deletions components/Video.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<video
v-if="props.src && !error"
autoplay
ref="video"
v-if="props.src && !showPoster"
muted
loop
playsinline
Expand All @@ -12,17 +12,19 @@
:src="props.src"
type="video/mp4"
class="hidden"
:onerror="fallback"
:onerror="
() => {
showPoster = true
}
"
/>
</video>
<Image v-else :src="props.poster" />
</template>

<script setup lang="ts">
const error = ref(false)
function fallback() {
error.value = true
}
const video = ref<HTMLVideoElement>()
const showPoster = ref(false)
const props = defineProps({
src: {
type: String,
Expand All @@ -34,4 +36,15 @@ const props = defineProps({
default: '',
},
})
// allows nuxt image to find poster for prerendering
if (process.env.NODE_ENV === 'prerender') {
showPoster.value = true
}
onMounted(() => {
video.value?.play().catch((e) => {
showPoster.value = true
})
})
</script>
18 changes: 12 additions & 6 deletions composables/useScrollCallback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const useScrollCallback = () => {
let cb: () => void

function scrollToCb(top: number, callback: () => void) {
// console.log('log, enter scrollToCb')
cb = callback
topRound = Math.round(top)

Expand All @@ -30,10 +31,18 @@ export const useScrollCallback = () => {
onScroll()
}

function exitScrollToCb() {
win.removeEventListener('scroll', onScroll)
if (scrollToInterval) clearInterval(scrollToInterval)
scrollToInterval = null
cb = () => {}
// console.log('log, exitScrollToCb')s
}

function onScroll() {
if (Math.round(win.scrollY) === topRound) {
win.removeEventListener('scroll', onScroll)
if (scrollToInterval) clearTimeout(scrollToInterval)
if (scrollToInterval) clearInterval(scrollToInterval)
scrollToInterval = null
cb()
}
Expand All @@ -44,11 +53,8 @@ export const useScrollCallback = () => {
})

onUnmounted(() => {
if (scrollToInterval) clearInterval(scrollToInterval)
scrollToInterval = null
win.removeEventListener('scroll', onScroll)
cb = () => {}
exitScrollToCb()
})

return { scrollToCb }
return { scrollToCb, exitScrollToCb }
}
Loading

0 comments on commit 7e29e89

Please sign in to comment.