Skip to content

Commit 78b84c0

Browse files
committed
docs(useIntersection): Adding advanced demo
1 parent fd9de76 commit 78b84c0

File tree

2 files changed

+87
-0
lines changed

2 files changed

+87
-0
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<template>
2+
<div class="section">
3+
<div class="intersection-adv" v-for="el in divElements">
4+
<use-intersection-element-demo
5+
class="intersection-adv__el"
6+
:options="intersectionOpts"
7+
@change="handleIntersectionChange"
8+
>
9+
<video controls loop>
10+
<source src=http://techslides.com/demos/sample-videos/small.mp4
11+
type=video/mp4>
12+
</video>
13+
</use-intersection-element-demo>
14+
</div>
15+
</div>
16+
</template>
17+
18+
<script lang="ts">
19+
import Vue from 'vue'
20+
import UseIntersectionElementDemo from './UseIntersectionElementDemo.vue'
21+
22+
export default Vue.extend({
23+
name: 'UseIntersectionDemo',
24+
components: { UseIntersectionElementDemo },
25+
setup() {
26+
const intersectionOpts = {
27+
root: null,
28+
threshold: 1
29+
}
30+
31+
const divElements = new Array(100)
32+
33+
const handleIntersectionChange = ({
34+
target,
35+
intersectionRatio
36+
}: IntersectionObserverEntry) => {
37+
const isVisible = intersectionRatio === 1
38+
const $video = target.querySelector('video')
39+
if (!$video) return
40+
41+
if (!isVisible) {
42+
if (!$video.paused) $video.pause()
43+
} else {
44+
if ($video.paused) $video.play()
45+
}
46+
}
47+
48+
return { divElements, intersectionOpts, handleIntersectionChange }
49+
}
50+
})
51+
</script>
52+
53+
<style>
54+
.section {
55+
padding: 20px 0;
56+
}
57+
58+
.intersection-adv {
59+
display: flex;
60+
align-items: center;
61+
justify-content: center;
62+
height: 920px;
63+
}
64+
65+
/* El */
66+
.intersection-adv__el {
67+
position: relative;
68+
}
69+
</style>

src/components/useIntersection/stories/useIntersection.story.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { storiesOf } from '@storybook/vue'
22
import path from 'path'
33
import StoryTitle from '@src/helpers/StoryTitle.vue'
44
import UseIntersectionDemo from './UseIntersectionDemo.vue'
5+
import UseIntersectionAdvancedDemo from './UseIntersectionAdvancedDemo.vue'
56

67
const functionName = 'useIntersection'
78
const functionPath = path.resolve(__dirname, '..')
@@ -23,6 +24,23 @@ const basicDemo = () => ({
2324
</div>`
2425
})
2526

27+
const advancedDemo = () => ({
28+
components: { StoryTitle, demo: UseIntersectionAdvancedDemo },
29+
template: `
30+
<div class="container">
31+
<story-title
32+
function-path="${functionPath}"
33+
source-name="${functionName}"
34+
demo-name="UseIntersectionAdvancedDemo.vue"
35+
>
36+
<template v-slot:title>Advanced Demo</template>
37+
<template v-slot:intro></template>
38+
</story-title>
39+
<demo />
40+
</div>`
41+
})
42+
2643
storiesOf('sensors|useIntersection', module)
2744
.addParameters({ notes })
2845
.add('Demo', basicDemo)
46+
.add('Advanced Demo', advancedDemo)

0 commit comments

Comments
 (0)