Skip to content

Commit 3c739dc

Browse files
committed
add an example
1 parent 94f5b26 commit 3c739dc

2 files changed

Lines changed: 48 additions & 0 deletions

File tree

cssom-view/Overview.html

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,31 @@ <h3 id=the-stylemedia-interface><span class=secno>4.1. </span>The <code
611611
href="#task">task</a> was <a href="#queue-a-task" title="queue a
612612
task">queued</a>.
613613

614+
<div class=example>
615+
<p>A simple piece of code that detects changes in the orientation of the
616+
viewport can be written as follows:</p>
617+
618+
<pre><code>function handleOrientationChange(landscape) {
619+
if(landscape)
620+
&hellip;
621+
else
622+
&hellip;
623+
}
624+
styleMedia.addMediumListener("(orientation:landscape)", handleOrientationChange)</code></pre>
625+
626+
<p>A more generic handler for media query changes could be written as
627+
follows:</p>
628+
629+
<pre><code>function handleMediaQueryChange(query, matches) {
630+
&hellip;
631+
}
632+
function addMediumListener(query) {
633+
styleMedia.addMediumListener(query,
634+
function(matches) { handleMediaQueryChange(query, matches) }
635+
)
636+
}</code></pre>
637+
</div>
638+
614639
<h3 id=the-screen-interface><span class=secno>4.2. </span>The <code
615640
title="">Screen</code> Interface</h3>
616641

cssom-view/Overview.src.html

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,29 @@ <h3 id="the-stylemedia-interface">The <code title="">StyleMedia</code> Interface
454454
media query matches the state of the rendered <code>Document</code> at the
455455
time the <span>task</span> was
456456
<span title="queue a task">queued</span>.</p>
457+
458+
<div class="example">
459+
<p>A simple piece of code that detects changes in the orientation of the
460+
viewport can be written as follows:</p>
461+
<pre><code>function handleOrientationChange(landscape) {
462+
if(landscape)
463+
&hellip;
464+
else
465+
&hellip;
466+
}
467+
styleMedia.addMediumListener("(orientation:landscape)", handleOrientationChange)</code></pre>
468+
469+
<p>A more generic handler for media query changes could be written as
470+
follows:</p>
471+
<pre><code>function handleMediaQueryChange(query, matches) {
472+
&hellip;
473+
}
474+
function addMediumListener(query) {
475+
styleMedia.addMediumListener(query,
476+
function(matches) { handleMediaQueryChange(query, matches) }
477+
)
478+
}</code></pre>
479+
</div>
457480

458481

459482

0 commit comments

Comments
 (0)