File tree Expand file tree Collapse file tree 2 files changed +87
-0
lines changed
src/components/useIntersection/stories Expand file tree Collapse file tree 2 files changed +87
-0
lines changed Original file line number Diff line number Diff line change 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 >
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import { storiesOf } from '@storybook/vue'
22import path from 'path'
33import StoryTitle from '@src/helpers/StoryTitle.vue'
44import UseIntersectionDemo from './UseIntersectionDemo.vue'
5+ import UseIntersectionAdvancedDemo from './UseIntersectionAdvancedDemo.vue'
56
67const functionName = 'useIntersection'
78const 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+
2643storiesOf ( 'sensors|useIntersection' , module )
2744 . addParameters ( { notes } )
2845 . add ( 'Demo' , basicDemo )
46+ . add ( 'Advanced Demo' , advancedDemo )
You can’t perform that action at this time.
0 commit comments