Skip to content

Commit 9cecc89

Browse files
committed
Move Viewport example
Signed-off-by: Shubham Gupta <shubham.gupta@chromium.org>
1 parent 44dd159 commit 9cecc89

2 files changed

Lines changed: 71 additions & 73 deletions

File tree

‎css-viewport-1/Overview.bs‎

Lines changed: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,74 @@ larger than the [=initial viewport=] or the zoom factor
130130
causes only parts of the [=layout viewport=] to be visible,
131131
the UA should offer a scrolling or panning mechanism.
132132

133+
The <a>visual viewport</a>'s <a>scrolling area</a> is another <a>viewport</a>,
134+
the <a>layout viewport</a>.
135+
136+
<style>
137+
@keyframes lvmove {
138+
0%, 10%, 20% { transform: translate(0, 100px); }
139+
30%, 50%, 70% { transform: translate(0, 150px); }
140+
80%,100% { transform: translate(0, 100px); }
141+
}
142+
@keyframes vvmove {
143+
0%, 10% { transform: translate(70px, 150px); }
144+
30%, 50% { transform: translate(70px, 250px); }
145+
80%, 90% { transform: translate(70px, 100px); }
146+
100% { transform: translate(70px, 150px); }
147+
}
148+
#lv {
149+
transform: translate(0, 100px);
150+
animation: lvmove linear 3s infinite;
151+
}
152+
#vv {
153+
transform: translate(20px, 150px);
154+
animation: vvmove linear 3s infinite;
155+
}
156+
.paused #lv {
157+
animation-play-state: paused;
158+
}
159+
.paused #vv {
160+
animation-play-state: paused;
161+
}
162+
</style>
163+
<div class="example paused" id="example-vvanimation">
164+
<p>
165+
This animation shows an example of a zoomed in visual viewport being "panned" around (for
166+
example, by a user performing a touch drag). The page is scaled so that the layout viewport
167+
is larger than the visual viewport.
168+
</p>
169+
<p>
170+
A scroll delta is applied to the visual viewport first. When the visual viewport is at its
171+
extent, scroll delta will be applied to the layout viewport. This behavior is implemented by
172+
the [=viewport/perform a scroll=] steps.
173+
</p>
174+
<svg width="300" height="400">
175+
<rect width="100%" height="100%" fill="white" stroke="grey" stroke-width="3"/>
176+
<text x="10" y="30" font-family="Sans" font-size="25" fill="grey">
177+
Document
178+
</text>
179+
<g id="lv">
180+
<rect y="2" x="2" width="296" height="200" stroke="blue" fill="none" stroke-width="4"/>
181+
<text x="10" y="20" font-family="Sans" font-size="15" fill="blue">
182+
Layout Viewport
183+
</text>
184+
</g>
185+
<g id="vv">
186+
<rect y="2" x="2" width="148" height="100" stroke="red" fill="none" stroke-width="4"/>
187+
<text x="10" y="60" font-family="Sans" font-size="15" fill="red">
188+
Visual Viewport
189+
</text>
190+
</g>
191+
</svg>
192+
<br>
193+
<button id="vvanimationBtn">Toggle Animation</button>
194+
<script>
195+
document.getElementById('vvanimationBtn').onclick = () => {
196+
document.getElementById('example-vvanimation').classList.toggle('paused');
197+
};
198+
</script>
199+
</div>
200+
133201
It is recommended that initially the upper-left corners of the
134202
[=layout viewport=] and the window or viewing area are aligned if the
135203
base direction of the document is ltr. Similarly, that the upper-right
@@ -311,8 +379,6 @@ Issue: Specify extend-to-zoom behavior by the viewport meta tag
311379

312380
<h3 id="interactive-widget-section">''interactive-widget''</h3>
313381

314-
Issue: Move the definition of ''visual viewport'' from CSSOM-View to this spec.
315-
316382
The <dfn export><code>interactive-widget</code></dfn> property specifies the effect that interactive UI
317383
widgets have on the page's viewports. It defines whether widgets overlay a given viewport or whether
318384
the viewport is shrunken so that it remains fully visible while the widget is showing. Interactive

‎cssom-view-1/Overview.bs‎

Lines changed: 3 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ A <dfn export>scrolling box</dfn> of a <a>viewport</a> or element has two <dfn>o
130130
Note that the initial scroll position might not be aligned with the [=scrolling area origin=]
131131
depending on the [=content-distribution properties=], see [[css-align-3#overflow-scroll-position]].
132132

133-
The term <dfn>scrolling area</dfn> refers to a box of a <a>viewport</a> or an element that has the following edges, depending on the
133+
The term <dfn export>scrolling area</dfn> refers to a box of a <a>viewport</a> or an element that has the following edges, depending on the
134134
<a>viewport’s</a> or element's <a>scrolling box’s</a> <a>overflow directions</a>.
135135

136136
<table class="complex data">
@@ -293,74 +293,6 @@ The <dfn>ending edges</dfn> of a particular set of edges of a box or element are
293293
<dd>The top and right edges.
294294
</dl>
295295

296-
The <a>visual viewport</a>'s <a>scrolling area</a> is another <a>viewport</a>,
297-
the <a>layout viewport</a>.
298-
299-
<style>
300-
@keyframes lvmove {
301-
0%, 10%, 20% { transform: translate(0, 100px); }
302-
30%, 50%, 70% { transform: translate(0, 150px); }
303-
80%,100% { transform: translate(0, 100px); }
304-
}
305-
@keyframes vvmove {
306-
0%, 10% { transform: translate(70px, 150px); }
307-
30%, 50% { transform: translate(70px, 250px); }
308-
80%, 90% { transform: translate(70px, 100px); }
309-
100% { transform: translate(70px, 150px); }
310-
}
311-
#lv {
312-
transform: translate(0, 100px);
313-
animation: lvmove linear 3s infinite;
314-
}
315-
#vv {
316-
transform: translate(20px, 150px);
317-
animation: vvmove linear 3s infinite;
318-
}
319-
.paused #lv {
320-
animation-play-state: paused;
321-
}
322-
.paused #vv {
323-
animation-play-state: paused;
324-
}
325-
</style>
326-
<div class="example paused" id="example-vvanimation">
327-
<p>
328-
This animation shows an example of a zoomed in visual viewport being "panned" around (for
329-
example, by a user performing a touch drag). The page is scaled so that the layout viewport
330-
is larger than the visual viewport.
331-
</p>
332-
<p>
333-
A scroll delta is applied to the visual viewport first. When the visual viewport is at its
334-
extent, scroll delta will be applied to the layout viewport. This behavior is implemented by
335-
the [=viewport/perform a scroll=] steps.
336-
</p>
337-
<svg width="300" height="400">
338-
<rect width="100%" height="100%" fill="white" stroke="grey" stroke-width="3"/>
339-
<text x="10" y="30" font-family="Sans" font-size="25" fill="grey">
340-
Document
341-
</text>
342-
<g id="lv">
343-
<rect y="2" x="2" width="296" height="200" stroke="blue" fill="none" stroke-width="4"/>
344-
<text x="10" y="20" font-family="Sans" font-size="15" fill="blue">
345-
Layout Viewport
346-
</text>
347-
</g>
348-
<g id="vv">
349-
<rect y="2" x="2" width="148" height="100" stroke="red" fill="none" stroke-width="4"/>
350-
<text x="10" y="60" font-family="Sans" font-size="15" fill="red">
351-
Visual Viewport
352-
</text>
353-
</g>
354-
</svg>
355-
<br>
356-
<button id="vvanimationBtn">Toggle Animation</button>
357-
<script>
358-
document.getElementById('vvanimationBtn').onclick = () => {
359-
document.getElementById('example-vvanimation').classList.toggle('paused');
360-
};
361-
</script>
362-
</div>
363-
364296
The {{VisualViewport}} object has an <dfn for=visualviewport>associated document</dfn>, which is a {{Document}} object.
365297
It is the <a for="/">associated document</a> of the owner {{Window}} of {{VisualViewport}}. The <a>layout viewport</a>
366298
is the owner {{Window}}'s <a>viewport</a>.
@@ -498,8 +430,8 @@ Note: Conceptually, the visual viewport is scrolled until it "bumps up" against
498430
edge and then "pushes" the layout viewport by applying the scroll delta to the layout viewport.
499431
However, the scrolls in the steps above are computed ahead of time and applied in the opposite order
500432
so that the layout viewport is scrolled before the visual viewport. This is done for historical
501-
reasons to ensure consistent scroll event ordering. See the <a href="#example-vvanimation">example
502-
above</a> for a visual depiction.
433+
reasons to ensure consistent scroll event ordering. See the <a href="https://drafts.csswg.org/css-viewport/#example-vvanimation">example
434+
</a> for a visual depiction.
503435

504436
</div>
505437

0 commit comments

Comments
 (0)