@gitlab/ui 32.65.1 → 32.66.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/dist/components/utilities/intersection_observer/intersection_observer.documentation.js +1 -20
- package/dist/components/utilities/intersection_observer/intersection_observer.js +12 -0
- package/dist/utility_classes.css +1 -1
- package/dist/utility_classes.css.map +1 -1
- package/documentation/documented_stories.js +1 -0
- package/package.json +1 -1
- package/src/components/utilities/intersection_observer/intersection_observer.documentation.js +0 -23
- package/src/components/utilities/intersection_observer/intersection_observer.stories.js +91 -80
- package/src/components/utilities/intersection_observer/intersection_observer.vue +15 -0
- package/src/scss/utilities.scss +10 -0
- package/src/scss/utility-mixins/spacing.scss +6 -0
- package/dist/components/utilities/intersection_observer/examples/index.js +0 -19
- package/dist/components/utilities/intersection_observer/examples/intersection_observer.image.example.js +0 -62
- package/dist/components/utilities/intersection_observer/examples/intersection_observer.last_appeared.example.js +0 -83
- package/src/components/utilities/intersection_observer/examples/index.js +0 -23
- package/src/components/utilities/intersection_observer/examples/intersection_observer.image.example.vue +0 -29
- package/src/components/utilities/intersection_observer/examples/intersection_observer.last_appeared.example.vue +0 -43
package/package.json
CHANGED
package/src/components/utilities/intersection_observer/intersection_observer.documentation.js
CHANGED
|
@@ -1,28 +1,5 @@
|
|
|
1
|
-
import examples from './examples';
|
|
2
1
|
import * as description from './intersection_observer.md';
|
|
3
2
|
|
|
4
3
|
export default {
|
|
5
4
|
description,
|
|
6
|
-
examples,
|
|
7
|
-
propsInfo: {
|
|
8
|
-
options: {
|
|
9
|
-
additionalInfo: 'Extra options to pass directly to the intersection observer API.',
|
|
10
|
-
},
|
|
11
|
-
},
|
|
12
|
-
events: [
|
|
13
|
-
{
|
|
14
|
-
event: 'appear',
|
|
15
|
-
description: 'Emitted when the element appears on the page',
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
event: 'disappear',
|
|
19
|
-
description: 'Emitted when the element disappears from the page',
|
|
20
|
-
},
|
|
21
|
-
],
|
|
22
|
-
slots: [
|
|
23
|
-
{
|
|
24
|
-
slot: 'default',
|
|
25
|
-
description: "The element you wish to observe, or a fallback if the observer doesn't work.",
|
|
26
|
-
},
|
|
27
|
-
],
|
|
28
5
|
};
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { documentedStoriesOf } from '../../../../documentation/documented_stories';
|
|
2
1
|
import { GlIntersectionObserver } from '../../../../index';
|
|
3
2
|
import readme from './intersection_observer.md';
|
|
4
3
|
|
|
@@ -31,17 +30,16 @@ const generateItems = (startingId = 0) => {
|
|
|
31
30
|
});
|
|
32
31
|
};
|
|
33
32
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
return this.isInView ? 'The observer is in view' : 'The observer is not in view';
|
|
42
|
-
},
|
|
33
|
+
export const Default = () => ({
|
|
34
|
+
components,
|
|
35
|
+
data: commonData,
|
|
36
|
+
methods: commonMethods,
|
|
37
|
+
computed: {
|
|
38
|
+
visibility() {
|
|
39
|
+
return this.isInView ? 'The observer is in view' : 'The observer is not in view';
|
|
43
40
|
},
|
|
44
|
-
|
|
41
|
+
},
|
|
42
|
+
template: `
|
|
45
43
|
<div style="height: 200px; overflow-y: scroll;">
|
|
46
44
|
<h1>{{ visibility }}</h1>
|
|
47
45
|
<p>This one is a hard one to demonstrate as it's invisible by nature.</p>
|
|
@@ -55,26 +53,27 @@ documentedStoriesOf('utilities/intersection-observer', readme)
|
|
|
55
53
|
/>
|
|
56
54
|
<p>This line appears just after the observer.</p>
|
|
57
55
|
</div>
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
56
|
+
`,
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
export const BigTable = () => ({
|
|
60
|
+
components,
|
|
61
|
+
data() {
|
|
62
|
+
return {
|
|
63
|
+
values: Array(100)
|
|
64
|
+
.fill(1)
|
|
65
|
+
.map(() => Array(10).fill(0)),
|
|
66
|
+
};
|
|
67
|
+
},
|
|
68
|
+
methods: {
|
|
69
|
+
update(row, col, { intersectionRatio }) {
|
|
70
|
+
this.$set(this.values[row], col, intersectionRatio);
|
|
68
71
|
},
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
this.$set(this.values[row], col, intersectionRatio);
|
|
72
|
-
},
|
|
73
|
-
disappear(row, col) {
|
|
74
|
-
this.values[row][col] = 0;
|
|
75
|
-
},
|
|
72
|
+
disappear(row, col) {
|
|
73
|
+
this.values[row][col] = 0;
|
|
76
74
|
},
|
|
77
|
-
|
|
75
|
+
},
|
|
76
|
+
template: `
|
|
78
77
|
<div style="height: 600px; overflow-y: scroll;">
|
|
79
78
|
<table>
|
|
80
79
|
<tr v-for="(cols, row) in values" :key="row">
|
|
@@ -87,20 +86,21 @@ documentedStoriesOf('utilities/intersection-observer', readme)
|
|
|
87
86
|
</table>
|
|
88
87
|
</div>
|
|
89
88
|
`,
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
export const LazyLoadedImage = () => ({
|
|
92
|
+
components,
|
|
93
|
+
data: commonData,
|
|
94
|
+
methods: commonMethods,
|
|
95
|
+
computed: {
|
|
96
|
+
imageUrl() {
|
|
97
|
+
// If the image is in view, return the high res one. If not return nothing, or a low res one
|
|
98
|
+
return this.isInView
|
|
99
|
+
? '../../img/gitlab-summit-south-africa.jpg'
|
|
100
|
+
: '../../img/gitlab-summit-south-africa-min.jpg';
|
|
102
101
|
},
|
|
103
|
-
|
|
102
|
+
},
|
|
103
|
+
template: `
|
|
104
104
|
<div>
|
|
105
105
|
<p>The image below will load a low-res version until it appears on the poage, then it will switch out for a higher res version.</p>
|
|
106
106
|
<p>It's also set up to switch back to the low res version when it disappears off the page. This is not what you would usually do for lazily loaded images, but it helps to demonstrate the effect in this example.</p>
|
|
@@ -111,42 +111,53 @@ documentedStoriesOf('utilities/intersection-observer', readme)
|
|
|
111
111
|
<img :src="imageUrl" style="max-width: 100%; height: auto;"/>
|
|
112
112
|
</gl-intersection-observer>
|
|
113
113
|
</div>
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
114
|
+
`,
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
export const InfiniteScrolling = () => ({
|
|
118
|
+
components,
|
|
119
|
+
data: () => ({
|
|
120
|
+
items: generateItems(),
|
|
121
|
+
}),
|
|
122
|
+
computed: {
|
|
123
|
+
lastItemId() {
|
|
124
|
+
return this.items[this.items.length - 1].id;
|
|
125
|
+
},
|
|
126
|
+
endOfList() {
|
|
127
|
+
return this.lastItemId >= 1000;
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
methods: {
|
|
131
|
+
fetchMoreItems() {
|
|
132
|
+
if (!this.endOfList) {
|
|
133
|
+
this.items.push(...generateItems(this.lastItemId));
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
template: `
|
|
138
|
+
<div>
|
|
139
|
+
<h2>Infinitely scrollable list</h2>
|
|
140
|
+
<p>This data will procedurally generate 1000 items, 20 at a time</p>
|
|
141
|
+
<ul>
|
|
142
|
+
<li v-for="item in items" :key="item.id">{{ item.title }}</li>
|
|
143
|
+
</ul>
|
|
144
|
+
<gl-intersection-observer v-if="!endOfList" @appear="fetchMoreItems">
|
|
145
|
+
<button @click="fetchMoreItems">Fetch more items</button>
|
|
146
|
+
</gl-intersection-observer>
|
|
147
|
+
</div>
|
|
148
|
+
`,
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
export default {
|
|
152
|
+
title: 'utilities/intersection-observer',
|
|
153
|
+
component: GlIntersectionObserver,
|
|
154
|
+
parameters: {
|
|
155
|
+
knobs: { disable: true },
|
|
156
|
+
storyshots: { disable: true },
|
|
157
|
+
docs: {
|
|
158
|
+
description: {
|
|
159
|
+
component: readme,
|
|
137
160
|
},
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
<p>This data will procedurally generate 1000 items, 20 at a time</p>
|
|
142
|
-
<ul>
|
|
143
|
-
<li v-for="item in items" :key="item.id">{{ item.title }}</li>
|
|
144
|
-
</ul>
|
|
145
|
-
<gl-intersection-observer v-if="!endOfList" @appear="fetchMoreItems">
|
|
146
|
-
<button @click="fetchMoreItems">Fetch more items</button>
|
|
147
|
-
</gl-intersection-observer>
|
|
148
|
-
</div>
|
|
149
|
-
`,
|
|
150
|
-
}),
|
|
151
|
-
{ storyshots: false }
|
|
152
|
-
);
|
|
161
|
+
},
|
|
162
|
+
},
|
|
163
|
+
};
|
|
@@ -13,6 +13,9 @@ const getObserver = memoize(
|
|
|
13
13
|
export default {
|
|
14
14
|
name: 'GlIntersectionObserver',
|
|
15
15
|
props: {
|
|
16
|
+
/**
|
|
17
|
+
* Extra options to pass directly to the intersection observer API.
|
|
18
|
+
*/
|
|
16
19
|
options: {
|
|
17
20
|
type: Object,
|
|
18
21
|
required: false,
|
|
@@ -23,11 +26,20 @@ export default {
|
|
|
23
26
|
const observer = getObserver(this.options);
|
|
24
27
|
|
|
25
28
|
this.$el.$_gl_intersectionHandler = (entry) => {
|
|
29
|
+
/**
|
|
30
|
+
* Emitted when the element's visibility changes
|
|
31
|
+
*/
|
|
26
32
|
this.$emit('update', entry);
|
|
27
33
|
|
|
28
34
|
if (entry.isIntersecting) {
|
|
35
|
+
/**
|
|
36
|
+
* Emitted when the element appears on the page
|
|
37
|
+
*/
|
|
29
38
|
this.$emit('appear');
|
|
30
39
|
} else {
|
|
40
|
+
/**
|
|
41
|
+
* Emitted when the element disappears from the page
|
|
42
|
+
*/
|
|
31
43
|
this.$emit('disappear');
|
|
32
44
|
}
|
|
33
45
|
};
|
|
@@ -47,6 +59,9 @@ export default {
|
|
|
47
59
|
|
|
48
60
|
<template>
|
|
49
61
|
<div>
|
|
62
|
+
<!--
|
|
63
|
+
@slot The element you wish to observe, or a fallback if the observer doesn't work.
|
|
64
|
+
-->
|
|
50
65
|
<slot></slot>
|
|
51
66
|
</div>
|
|
52
67
|
</template>
|
package/src/scss/utilities.scss
CHANGED
|
@@ -5616,6 +5616,16 @@
|
|
|
5616
5616
|
margin-left: #{$gl-spacing-scale-3} !important;
|
|
5617
5617
|
}
|
|
5618
5618
|
}
|
|
5619
|
+
.gl-gap-x-5 {
|
|
5620
|
+
> * + * {
|
|
5621
|
+
margin-left: #{$gl-spacing-scale-5};
|
|
5622
|
+
}
|
|
5623
|
+
}
|
|
5624
|
+
.gl-gap-x-5\! {
|
|
5625
|
+
> * + * {
|
|
5626
|
+
margin-left: #{$gl-spacing-scale-5} !important;
|
|
5627
|
+
}
|
|
5628
|
+
}
|
|
5619
5629
|
.gl-xs-mb-3 {
|
|
5620
5630
|
@include gl-media-breakpoint-down(sm) {
|
|
5621
5631
|
margin-bottom: $gl-spacing-scale-3;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import ImageExample from './intersection_observer.image.example';
|
|
2
|
-
import LastAppearedExample from './intersection_observer.last_appeared.example';
|
|
3
|
-
|
|
4
|
-
var index = [{
|
|
5
|
-
name: 'Intersection observer',
|
|
6
|
-
items: [{
|
|
7
|
-
id: 'intersection-observer-last-appeared',
|
|
8
|
-
name: 'Last appeared at',
|
|
9
|
-
description: 'Logs when the component last appeared on the screen',
|
|
10
|
-
component: LastAppearedExample
|
|
11
|
-
}, {
|
|
12
|
-
id: 'intersection-observer-lazy-loaded-image',
|
|
13
|
-
name: 'Lazy loaded image',
|
|
14
|
-
description: "This image switches between a gif and a still image when it's on or off the screen",
|
|
15
|
-
component: ImageExample
|
|
16
|
-
}]
|
|
17
|
-
}];
|
|
18
|
-
|
|
19
|
-
export default index;
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import __vue_normalize__ from 'vue-runtime-helpers/dist/normalize-component.js';
|
|
2
|
-
|
|
3
|
-
var script = {
|
|
4
|
-
data: () => ({
|
|
5
|
-
isInView: false
|
|
6
|
-
}),
|
|
7
|
-
computed: {
|
|
8
|
-
imageUrl() {
|
|
9
|
-
// If the image is in view, return the high res one. If not return nothing, or a low res one
|
|
10
|
-
return this.isInView ? '../../img/gitlab-summit-south-africa.jpg' : '../../img/gitlab-summit-south-africa-min.jpg';
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
},
|
|
14
|
-
methods: {
|
|
15
|
-
appear() {
|
|
16
|
-
this.isInView = true;
|
|
17
|
-
},
|
|
18
|
-
|
|
19
|
-
disappear() {
|
|
20
|
-
this.isInView = false;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
/* script */
|
|
27
|
-
const __vue_script__ = script;
|
|
28
|
-
|
|
29
|
-
/* template */
|
|
30
|
-
var __vue_render__ = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('gl-intersection-observer',{on:{"appear":_vm.appear,"disappear":_vm.disappear}},[_c('img',{staticStyle:{"max-width":"100%","height":"auto"},attrs:{"src":_vm.imageUrl}})])};
|
|
31
|
-
var __vue_staticRenderFns__ = [];
|
|
32
|
-
|
|
33
|
-
/* style */
|
|
34
|
-
const __vue_inject_styles__ = undefined;
|
|
35
|
-
/* scoped */
|
|
36
|
-
const __vue_scope_id__ = undefined;
|
|
37
|
-
/* module identifier */
|
|
38
|
-
const __vue_module_identifier__ = undefined;
|
|
39
|
-
/* functional template */
|
|
40
|
-
const __vue_is_functional_template__ = false;
|
|
41
|
-
/* style inject */
|
|
42
|
-
|
|
43
|
-
/* style inject SSR */
|
|
44
|
-
|
|
45
|
-
/* style inject shadow dom */
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const __vue_component__ = __vue_normalize__(
|
|
50
|
-
{ render: __vue_render__, staticRenderFns: __vue_staticRenderFns__ },
|
|
51
|
-
__vue_inject_styles__,
|
|
52
|
-
__vue_script__,
|
|
53
|
-
__vue_scope_id__,
|
|
54
|
-
__vue_is_functional_template__,
|
|
55
|
-
__vue_module_identifier__,
|
|
56
|
-
false,
|
|
57
|
-
undefined,
|
|
58
|
-
undefined,
|
|
59
|
-
undefined
|
|
60
|
-
);
|
|
61
|
-
|
|
62
|
-
export default __vue_component__;
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import __vue_normalize__ from 'vue-runtime-helpers/dist/normalize-component.js';
|
|
2
|
-
|
|
3
|
-
var script = {
|
|
4
|
-
data: () => ({
|
|
5
|
-
appearedAt: null,
|
|
6
|
-
now: null,
|
|
7
|
-
interval: null
|
|
8
|
-
}),
|
|
9
|
-
computed: {
|
|
10
|
-
secondsSinceAppearance() {
|
|
11
|
-
if (!this.appearedAt) {
|
|
12
|
-
return 0;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
return Math.floor((this.now - this.appearedAt) / 1000);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
},
|
|
19
|
-
|
|
20
|
-
destroyed() {
|
|
21
|
-
this.clearInterval();
|
|
22
|
-
},
|
|
23
|
-
|
|
24
|
-
methods: {
|
|
25
|
-
appear() {
|
|
26
|
-
this.clearInterval();
|
|
27
|
-
this.interval = setInterval(this.tick, 1000);
|
|
28
|
-
this.tick();
|
|
29
|
-
this.appearedAt = this.now;
|
|
30
|
-
},
|
|
31
|
-
|
|
32
|
-
disappear() {
|
|
33
|
-
this.clearInterval();
|
|
34
|
-
},
|
|
35
|
-
|
|
36
|
-
clearInterval() {
|
|
37
|
-
clearInterval(this.interval);
|
|
38
|
-
},
|
|
39
|
-
|
|
40
|
-
tick() {
|
|
41
|
-
this.now = new Date().getTime();
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
/* script */
|
|
48
|
-
const __vue_script__ = script;
|
|
49
|
-
|
|
50
|
-
/* template */
|
|
51
|
-
var __vue_render__ = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('gl-intersection-observer',{on:{"appear":_vm.appear,"disappear":_vm.disappear}},[_c('span',[_vm._v("Last appeared "+_vm._s(_vm.secondsSinceAppearance)+" seconds ago")])])};
|
|
52
|
-
var __vue_staticRenderFns__ = [];
|
|
53
|
-
|
|
54
|
-
/* style */
|
|
55
|
-
const __vue_inject_styles__ = undefined;
|
|
56
|
-
/* scoped */
|
|
57
|
-
const __vue_scope_id__ = undefined;
|
|
58
|
-
/* module identifier */
|
|
59
|
-
const __vue_module_identifier__ = undefined;
|
|
60
|
-
/* functional template */
|
|
61
|
-
const __vue_is_functional_template__ = false;
|
|
62
|
-
/* style inject */
|
|
63
|
-
|
|
64
|
-
/* style inject SSR */
|
|
65
|
-
|
|
66
|
-
/* style inject shadow dom */
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
const __vue_component__ = __vue_normalize__(
|
|
71
|
-
{ render: __vue_render__, staticRenderFns: __vue_staticRenderFns__ },
|
|
72
|
-
__vue_inject_styles__,
|
|
73
|
-
__vue_script__,
|
|
74
|
-
__vue_scope_id__,
|
|
75
|
-
__vue_is_functional_template__,
|
|
76
|
-
__vue_module_identifier__,
|
|
77
|
-
false,
|
|
78
|
-
undefined,
|
|
79
|
-
undefined,
|
|
80
|
-
undefined
|
|
81
|
-
);
|
|
82
|
-
|
|
83
|
-
export default __vue_component__;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import ImageExample from './intersection_observer.image.example.vue';
|
|
2
|
-
import LastAppearedExample from './intersection_observer.last_appeared.example.vue';
|
|
3
|
-
|
|
4
|
-
export default [
|
|
5
|
-
{
|
|
6
|
-
name: 'Intersection observer',
|
|
7
|
-
items: [
|
|
8
|
-
{
|
|
9
|
-
id: 'intersection-observer-last-appeared',
|
|
10
|
-
name: 'Last appeared at',
|
|
11
|
-
description: 'Logs when the component last appeared on the screen',
|
|
12
|
-
component: LastAppearedExample,
|
|
13
|
-
},
|
|
14
|
-
{
|
|
15
|
-
id: 'intersection-observer-lazy-loaded-image',
|
|
16
|
-
name: 'Lazy loaded image',
|
|
17
|
-
description:
|
|
18
|
-
"This image switches between a gif and a still image when it's on or off the screen",
|
|
19
|
-
component: ImageExample,
|
|
20
|
-
},
|
|
21
|
-
],
|
|
22
|
-
},
|
|
23
|
-
];
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
export default {
|
|
3
|
-
data: () => ({
|
|
4
|
-
isInView: false,
|
|
5
|
-
}),
|
|
6
|
-
computed: {
|
|
7
|
-
imageUrl() {
|
|
8
|
-
// If the image is in view, return the high res one. If not return nothing, or a low res one
|
|
9
|
-
return this.isInView
|
|
10
|
-
? '../../img/gitlab-summit-south-africa.jpg'
|
|
11
|
-
: '../../img/gitlab-summit-south-africa-min.jpg';
|
|
12
|
-
},
|
|
13
|
-
},
|
|
14
|
-
methods: {
|
|
15
|
-
appear() {
|
|
16
|
-
this.isInView = true;
|
|
17
|
-
},
|
|
18
|
-
disappear() {
|
|
19
|
-
this.isInView = false;
|
|
20
|
-
},
|
|
21
|
-
},
|
|
22
|
-
};
|
|
23
|
-
</script>
|
|
24
|
-
|
|
25
|
-
<template>
|
|
26
|
-
<gl-intersection-observer @appear="appear" @disappear="disappear">
|
|
27
|
-
<img :src="imageUrl" style="max-width: 100%; height: auto" />
|
|
28
|
-
</gl-intersection-observer>
|
|
29
|
-
</template>
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
export default {
|
|
3
|
-
data: () => ({
|
|
4
|
-
appearedAt: null,
|
|
5
|
-
now: null,
|
|
6
|
-
interval: null,
|
|
7
|
-
}),
|
|
8
|
-
computed: {
|
|
9
|
-
secondsSinceAppearance() {
|
|
10
|
-
if (!this.appearedAt) {
|
|
11
|
-
return 0;
|
|
12
|
-
}
|
|
13
|
-
return Math.floor((this.now - this.appearedAt) / 1000);
|
|
14
|
-
},
|
|
15
|
-
},
|
|
16
|
-
destroyed() {
|
|
17
|
-
this.clearInterval();
|
|
18
|
-
},
|
|
19
|
-
methods: {
|
|
20
|
-
appear() {
|
|
21
|
-
this.clearInterval();
|
|
22
|
-
this.interval = setInterval(this.tick, 1000);
|
|
23
|
-
this.tick();
|
|
24
|
-
this.appearedAt = this.now;
|
|
25
|
-
},
|
|
26
|
-
disappear() {
|
|
27
|
-
this.clearInterval();
|
|
28
|
-
},
|
|
29
|
-
clearInterval() {
|
|
30
|
-
clearInterval(this.interval);
|
|
31
|
-
},
|
|
32
|
-
tick() {
|
|
33
|
-
this.now = new Date().getTime();
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
};
|
|
37
|
-
</script>
|
|
38
|
-
|
|
39
|
-
<template>
|
|
40
|
-
<gl-intersection-observer @appear="appear" @disappear="disappear">
|
|
41
|
-
<span>Last appeared {{ secondsSinceAppearance }} seconds ago</span>
|
|
42
|
-
</gl-intersection-observer>
|
|
43
|
-
</template>
|