Skip to content

Commit adcd2e7

Browse files
committed
feat(docs): QResizeObserver and QScrollObserver pages
1 parent e02e37c commit adcd2e7

File tree

7 files changed

+149
-170
lines changed

7 files changed

+149
-170
lines changed

docs/src/assets/menu.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -358,12 +358,12 @@ const components = [
358358
name: 'Observers',
359359
children: [
360360
{
361-
name: 'Element Resize Observer',
362-
path: 'element-resize-observer'
361+
name: 'Resize Observer (for Element)',
362+
path: 'resize-observer'
363363
},
364364
{
365-
name: 'Window Resize Observer',
366-
path: 'window-resize-observer'
365+
name: 'Scroll Observer',
366+
path: 'scroll-observer'
367367
}
368368
]
369369
},
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<template>
2+
<div class="q-pa-md q-gutter-md">
3+
<q-btn color="primary" push @click="setRandomSize" label="Set Random Size" />
4+
5+
<div :style="style" class="container bg-amber generic-border-radius glossy">
6+
<!--
7+
we listen for size changes on this next
8+
<div>, so we place the observer as direct child:
9+
-->
10+
<q-resize-observer @resize="onResize" />
11+
</div>
12+
13+
<div class="q-gutter-sm">
14+
Reported:
15+
<q-badge>width: {{ report.width }}</q-badge>
16+
<q-badge>height: {{ report.height }}</q-badge>
17+
</div>
18+
</div>
19+
</template>
20+
21+
<script>
22+
export default {
23+
data () {
24+
return {
25+
style: { width: '200px', height: '200px' },
26+
report: ''
27+
}
28+
},
29+
30+
methods: {
31+
onResize (size) {
32+
this.report = size
33+
// {
34+
// width: 20 // width of container (in px)
35+
// height: 50 // height of container (in px)
36+
// }
37+
},
38+
39+
setRandomSize () {
40+
this.style = {
41+
width: Math.floor(100 + Math.random() * 200) + 'px',
42+
height: Math.floor(100 + Math.random() * 200) + 'px'
43+
}
44+
}
45+
}
46+
}
47+
</script>
48+
49+
<style lang="stylus" scoped>
50+
.container
51+
transition width .3s, height .3s
52+
</style>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<template>
2+
<div class="q-pa-md">
3+
<pre class="q-ma-none container">{{ scrollInfo }}</pre>
4+
<q-scroll-observer @scroll="onScroll" />
5+
</div>
6+
</template>
7+
8+
<script>
9+
export default {
10+
data () {
11+
return {
12+
scrollInfo: {}
13+
}
14+
},
15+
16+
methods: {
17+
onScroll (info) {
18+
this.scrollInfo = info
19+
}
20+
}
21+
}
22+
</script>
23+
24+
<style lang="stylus" scoped>
25+
.container
26+
font-size 12px
27+
</style>

docs/src/pages/vue-components/element-resize-observer.md

Lines changed: 0 additions & 83 deletions
This file was deleted.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
title: Resize Observer (for Element)
3+
---
4+
QResizeObserver is a Quasar component that emits a `resize` event whenever the wrapping DOM element / component (defined as direct parent of QResizeObserver) changes its size (width and/or height). Note that no polling is involved, but overusing it is costly too.
5+
6+
## Installation
7+
<doc-installation components="QResizeObserver" />
8+
9+
## Usage
10+
<doc-example title="Basic" file="QResizeObserver/Basic" />
11+
12+
Please note that QResizeObserver will issue an event as soon as it gets rendered and attached to DOM, so you can have the initial size of the container.
13+
14+
## API
15+
<doc-api file="QResizeObserver" />
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
---
2+
title: Scroll Observer
3+
---
4+
QScrollObserveer is a Quasar component that emits a `scroll` event whenever the user scrolls the page or overflowed container with `.scroll` CSS class applied to it.
5+
6+
## Installation
7+
<doc-installation components="QScrollObserver" />
8+
9+
## Usage
10+
Scroll this page to see the example below in action.
11+
<doc-example title="Basic" file="QScrollObserver/Basic" />
12+
13+
## Determining Scrolling Container
14+
All components or directives in Quasar have a simple algorithm to determine the container that supports the scroll: it searches for a parent DOM element which has the `scroll` Quasar CSS Helper class attached to it. If none is found, then it considers that the scrolling takes place on the document itself.
15+
16+
Components like [QScrollArea](/vue-components/scroll-area), for example, respect this design and have the `scroll` class embedded into it, so that QScrollObservable (or any other scrolling component or directive) can successfully detect it and attach the necessary event handlers to it.
17+
18+
Please note that simply attaching `scroll` CSS class to a DOM element or on a Vue component will have no effect if the respective element is not overflowed (example, with: CSS `overflow: hidden` and a height smaller than its inner content height).
19+
20+
Example of good container:
21+
```html
22+
<!--
23+
Quasar CSS helper 'overflow-hidden' is
24+
equivalent to style="overflow: hidden"
25+
-->
26+
<div class="scroll overflow-hidden" style="height: 100px">
27+
...content expanding over the 100px height from container...
28+
<q-scroll-observer @scroll="scrollHandler" />
29+
30+
<!-- example with `v-scroll` directive -->
31+
<div v-scroll="scrollHandler">...</div>
32+
</div>
33+
```
34+
35+
One more example with QScrollArea:
36+
```html
37+
<q-scroll-area style="width: 400px; height: 500px;" class="bg-yellow">
38+
...content expanding over the 500px height from container...
39+
<q-scroll-observer @scroll="scrollHandler" />
40+
</q-scroll-area>
41+
```
42+
43+
## Layout Scrolling
44+
When scrolling on a Layout with a Page, rather than injecting a QScrollObservable (and by so doing registering additional scroll events) you can take advantage of [QLayout](/components/layout.html)´s `@scroll` event directly on your component defining the Layout.
45+
46+
```html
47+
<q-layout @scroll="scrollHandler">...</q-layout>
48+
```
49+
50+
## API
51+
<doc-api file="QScrollObserver" />

docs/src/pages/vue-components/window-resize-observer.md

Lines changed: 0 additions & 83 deletions
This file was deleted.

0 commit comments

Comments
 (0)