diff options
author | MDN <actions@users.noreply.github.com> | 2021-04-21 00:11:44 +0000 |
---|---|---|
committer | MDN <actions@users.noreply.github.com> | 2021-04-21 00:11:44 +0000 |
commit | de630426a538c1f77d7c59e66827cb75693ed95b (patch) | |
tree | ff14c2d2677ed2137a84d3c322fa2f62e206e63a /files/ja/web/api | |
parent | d7a27823444dc11c7ff40ca63a78b3b37ab82837 (diff) | |
download | translated-content-de630426a538c1f77d7c59e66827cb75693ed95b.tar.gz translated-content-de630426a538c1f77d7c59e66827cb75693ed95b.tar.bz2 translated-content-de630426a538c1f77d7c59e66827cb75693ed95b.zip |
[CRON] sync translated content
Diffstat (limited to 'files/ja/web/api')
-rw-r--r-- | files/ja/web/api/detecting_device_orientation/index.html | 228 | ||||
-rw-r--r-- | files/ja/web/api/document_object_model/events/index.html | 88 |
2 files changed, 0 insertions, 316 deletions
diff --git a/files/ja/web/api/detecting_device_orientation/index.html b/files/ja/web/api/detecting_device_orientation/index.html deleted file mode 100644 index 8dc09fea8b..0000000000 --- a/files/ja/web/api/detecting_device_orientation/index.html +++ /dev/null @@ -1,228 +0,0 @@ ---- -title: デバイスの方向の検出 -slug: Web/API/Detecting_device_orientation -tags: - - API - - Device Orientation - - Firefox OS - - Intermediate - - Mobile - - Motion - - Orientation - - Reference - - WebAPI -translation_of: Web/API/Detecting_device_orientation ---- -<div>{{SeeCompatTable}}</div> - -<p>Web を利用可能なデバイスは、自身の<strong>方向</strong>を特定できるようになってきました。つまりデバイスは、重力との関係による自身の向きの変化を示すデータを報告できます。特に携帯電話のようなハンドヘルドデバイスは、表示内容が直立し続けるよう自動的に回転させるためにこの情報を使用でき、画面の幅が高さより大きくなるようにデバイスを回転させたときは、Web コンテンツをワイドスクリーン表示にします。</p> - -<p>方向の情報を制御する JavaScript イベントが 2 つあります。ひとつは {{domxref("DeviceOrientationEvent")}} であり、加速度センサーがデバイスの方向の変化を検出したときに発生します。Orientation イベントが報告するデータを受け取って処理することで、ユーザがデバイスを動かすことによる方向や高さの変化に対してインタラクティブに応答できるようになります。</p> - -<p>もうひとつのイベントは {{domxref("DeviceMotionEvent")}} であり、加速度が変化したときに発生します。こちらは方向ではなく加速度の変化を監視することが、{{domxref("DeviceOrientationEvent")}} との違いです。一般的に {{domxref("DeviceMotionEvent")}} を検出できるセンサーには、可動部があるストレージ装置を保護するためラップトップパソコンに内蔵するものも含みます。{{domxref("DeviceOrientationEvent")}} は、モバイルデバイスでとても一般的です。</p> - -<h2 id="Processing_orientation_events" name="Processing_orientation_events">orientation イベントを処理する</h2> - -<p>方向の変化を受け取り始めるには、{{event("deviceorientation")}} イベントをリッスンします:</p> - -<div class="note"> -<p><strong>注記</strong>: <a href="https://github.com/dorukeker/gyronorm.js">gyronorm.js</a> は、モバイルデバイスの加速度センサーやジャイロスコープのデータを正規化するためのポリフィルです。これは、デバイスの方向のサポート状況の違いを克服するのに役立ちます。</p> -</div> - -<pre class="brush: js">window.addEventListener("deviceorientation", handleOrientation, true); -</pre> - -<p>イベントリスナ (この例では handleOrientation() という名前の JavaScript 関数) を登録すると、リスナ関数は最新の方向データとともに、周期的に呼び出されます。</p> - -<p>Orientation イベントは 4 つの値を持ちます:</p> - -<ul> - <li>{{domxref("DeviceOrientationEvent.absolute")}}</li> - <li>{{domxref("DeviceOrientationEvent.alpha")}}</li> - <li>{{domxref("DeviceOrientationEvent.beta")}}</li> - <li>{{domxref("DeviceOrientationEvent.gamma")}}</li> -</ul> - -<p>イベントハンドラ関数は以下のようなものです:</p> - -<pre class="brush: js">function handleOrientation(event) { - var absolute = event.absolute; - var alpha = event.alpha; - var beta = event.beta; - var gamma = event.gamma; - - // 新たな方向データに基づいて処理を行う -} -</pre> - -<h3 id="Orientation_values_explained" name="Orientation_values_explained">方向として示される値</h3> - -<p>それぞれの軸で報告される値は、標準座標系の軸を中心にした回転量を表します。これらは<a href="/ja/DOM/Orientation_and_motion_data_explained">方向および動きとして示されるデータ</a>の記事で詳しく説明しており、ここでは概要を記載します。</p> - -<ul> - <li>{{domxref("DeviceOrientationEvent.alpha")}} の値は z 軸を中心にしたデバイスの動きを表し、0 から 360 の範囲による度数で表されます。</li> - <li>{{domxref("DeviceOrientationEvent.beta")}} の値は x 軸を中心にしたデバイスの動きを表し、-180 から 180 の範囲の値による度数で表されます。これはデバイスの前後の動きです。</li> - <li>{{domxref("DeviceOrientationEvent.gamma")}} の値は y 軸を中心にしたデバイスの動きを表し、-90 から 90 の範囲の値による度数で表されます。これはデバイスの左右の動きです。</li> -</ul> - -<h3 id="Orientation_example" name="Orientation_example">例</h3> - -<p>このサンプルは方向を検出可能なデバイス上で、{{event("deviceorientation")}} イベントをサポートするブラウザを実行する場合に動作します。</p> - -<p>庭にボールがあると考えます:</p> - -<pre class="brush: html"><div class="garden"> - <div class="ball"></div> -</div> - -<pre class="output"></pre> -</pre> - -<p>庭の幅は 200 ピクセルであり (小さな庭です)、ボールは中心にあります:</p> - -<pre class="brush: css">.garden { - position: relative; - width : 200px; - height: 200px; - border: 5px solid #CCC; - border-radius: 10px; -} - -.ball { - position: absolute; - top : 90px; - left : 90px; - width : 20px; - height: 20px; - background: green; - border-radius: 100%; -} -</pre> - -<p>デバイスを動かすと、その動きに応じてボールが移動します:</p> - -<pre class="brush: js">var ball = document.querySelector('.ball'); -var garden = document.querySelector('.garden'); -var output = document.querySelector('.output'); - -var maxX = garden.clientWidth - ball.clientWidth; -var maxY = garden.clientHeight - ball.clientHeight; - -function handleOrientation(event) { - var x = event.beta; // -180 から 180 の範囲で角度を示す - var y = event.gamma; // -90 から 90 の範囲で角度を示す - - output.innerHTML = "beta : " + x + "\n"; - output.innerHTML += "gamma: " + y + "\n"; - - // デバイスをひっくり返したくはないため、 - // x の値を -90 から 90 の範囲に制限する - if (x > 90) { x = 90}; - if (x < -90) { x = -90}; - - // 計算を容易にするため、x および y の値の範囲を - // 0 から 180 に変換する - x += 90; - y += 90; - - // 10 は、ボールのサイズの半分である。 - // これにより、配置場所をボールの中心に合わせる - ball.style.top = (maxX*x/180 - 10) + "px"; - ball.style.left = (maxY*y/180 - 10) + "px"; -} - -window.addEventListener('deviceorientation', handleOrientation); -</pre> - -<p>結果を以下に示します:</p> - -<div>{{EmbedLiveSample('Orientation_example', '230', '260')}}</div> - -<div class="warning"> -<p><strong>警告:</strong> Chrome と Firefox では角度の扱い方が異なり、一部の軸の向きが逆になっています。</p> -</div> - -<h2 id="Processing_motion_events" name="Processing_motion_events">motion イベントを処理する</h2> - -<p>motion イベントは orientation イベントと同じ方法で扱えますが、イベント名は {{event("devicemotion")}} になります。</p> - -<pre class="brush: js">window.addEventListener("devicemotion", <em>handleMotion</em>, true);</pre> - -<p>実際どのように変化したかの情報は、<em>HandleMotion</em> 関数のパラメータとして渡す {{domxref("DeviceMotionEvent")}} オブジェクトが提供します。</p> - -<p>motion イベントは 4 つのプロパティを持ちます:</p> - -<ul> - <li>{{domxref("DeviceMotionEvent.acceleration")}}</li> - <li>{{domxref("DeviceMotionEvent.accelerationIncludingGravity")}}</li> - <li>{{domxref("DeviceMotionEvent.rotationRate")}}</li> - <li>{{domxref("DeviceMotionEvent.interval")}}</li> -</ul> - -<h3 id="Motion_values_explained" name="Motion_values_explained">動きとして示される値</h3> - -<p>{{domxref("DeviceMotionEvent")}} オブジェクトは Web 開発者に、デバイスの位置や方向が変化した速度の情報を提供します。変化量は 3 つの軸 (詳しくは<a href="/ja/docs/Web/Guide/DOM/Events/Orientation_and_motion_data_explained">方向および動きとして示されるデータ</a>をご覧ください) に沿って表します。</p> - -<p>{{domxref("DeviceMotionEvent.acceleration","acceleration")}} および {{domxref("DeviceMotionEvent.accelerationIncludingGravity","accelerationIncludingGravity")}} で対応する軸は以下のとおりです:</p> - -<ul> - <li><code>x</code>: 西から東へ向かう軸を表します。</li> - <li><code>y</code>: 南から北へ向かう軸を表します。</li> - <li><code>z</code>: 地面から直立する軸を表します。</li> -</ul> - -<p>{{domxref("DeviceMotionEvent.rotationRate","rotationRate")}} では状況が若干異なります。こちらの情報はそれぞれ以下のように対応します:</p> - -<ul> - <li><code>alpha</code>: スクリーン (デスクトップ環境ではキーボード) から直立する軸を表します。</li> - <li><code>beta</code>: スクリーンの面 (デスクトップ環境ではキーボード) の左から右へ向かう軸に沿った回転量を表します。</li> - <li><code>gamma</code>: スクリーンの面 (デスクトップ環境ではキーボード) の下から上へ向かう軸に沿った回転量を表します。</li> -</ul> - -<p>最後に {{domxref("DeviceMotionEvent.interval","interval")}} は、デバイスからデータを取得する間隔をミリ秒単位で表します。</p> - -<h2 id="Specifications" name="Specifications">仕様</h2> - -<table class="standard-table"> - <thead> - <tr> - <th scope="col">仕様書</th> - <th scope="col">策定状況</th> - <th scope="col">コメント</th> - </tr> - </thead> - <tbody> - <tr> - <td>{{SpecName('Device Orientation')}}</td> - <td>{{Spec2('Device Orientation')}}</td> - <td>最初の仕様</td> - </tr> - </tbody> -</table> - -<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザ実装状況</h2> - -<div> -<h3 id="DeviceMotionEvent"><code>DeviceMotionEvent</code></h3> - - - -<p>{{Compat("api.DeviceMotionEvent")}}</p> - -<h3 id="DeviceOrientationEvent"><code>DeviceOrientationEvent</code></h3> - -<div class="hidden">The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> and send us a pull request.</div> - -<p>{{Compat("api.DeviceOrientationEvent")}}</p> -</div> - -<h2 id="See_also" name="See_also">関連情報</h2> - -<ul> - <li>{{domxref("DeviceOrientationEvent")}}</li> - <li>{{domxref("DeviceMotionEvent")}}</li> - <li>レガシー化したイベントである <code><a href="/ja/docs/Web/Events/MozOrientation">MozOrientation</a></code></li> - <li><a href="/ja/docs/Web/Guide/DOM/Events/Orientation_and_motion_data_explained">Orientation and motion data explained</a></li> - <li><a href="/ja/docs/Web/Guide/DOM/Events/Using_device_orientation_with_3D_transforms">Using deviceorientation in 3D Transforms</a></li> - <li><a href="/ja/docs/Games/Workflows/HTML5_Gamedev_Phaser_Device_Orientation">Cyber Orb: 2D maze game with device orientation</a></li> -</ul> diff --git a/files/ja/web/api/document_object_model/events/index.html b/files/ja/web/api/document_object_model/events/index.html deleted file mode 100644 index 1d8b1974a6..0000000000 --- a/files/ja/web/api/document_object_model/events/index.html +++ /dev/null @@ -1,88 +0,0 @@ ---- -title: イベントと DOM -slug: Web/API/Document_Object_Model/Events -tags: - - DOM - - Guide - - ガイド -translation_of: Web/API/Document_Object_Model/Events ---- -<div>{{DefaultAPISidebar("DOM")}}</div> - -<h2 id="Introduction" name="Introduction">はじめに</h2> - -<p>この章では DOM のイベントモデルを説明します。この <a href="http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-Event">Event</a> インターフェイス自身は、 DOM のノード上にイベントを登録する為のインターフェイスと同様であり、<a href="/ja/docs/Web/API/EventTarget/addEventListener">イベントリスナー</a>であるとも言えます。いくつかの長い例は、様々な Event インターフェイスがどのように他と関連するかを示します。</p> - -<p><a href="http://www.w3.org/TR/DOM-Level-3-Events/#dom-event-architecture">DOM レベル 3 イベントの原案</a>に、DOM を通して 3 つのフェーズから構成されるイベントフローを明確に説明した素晴らしい説明図があります。</p> - -<p>また、イベントが DOM 内をどのように伝播するかについては更に詳細なコード例、<a href="/ja/docs/DOM/DOM_Reference/Examples#Example_5.3A_Event_Propagation">例 5: イベント伝播 (propagation)</a> を参照してください。</p> - -<h2 id="DOM_event_handler_List" name="DOM_event_handler_List">イベントリスナーの登録</h2> - -<p>DOM の要素にイベントハンドラーを登録する方法は 3 つあります。</p> - -<h3 id="EventTarget.addEventListener" name="EventTarget.addEventListener">{{domxref("EventTarget.addEventListener")}}</h3> - -<pre class="brush: js notranslate">// myButton は button 要素だと仮定します -myButton.addEventListener('click', greet, false); -function greet(event){ - // print and have a look at the event object - // always print arguments in case of overlooking any other arguments - console.log('greet:', arguments) - alert('hello world') -} -</pre> - -<p>これが最近のウェブページで使われる方法です。</p> - -<div class="blockIndicator note"> -<p><strong>注:</strong> Internet Explorer 6 から 8 はこの方法をサポートせず、 {{domxref("EventTarget.attachEvent")}} という似た API を代わりにサポートします。ブラウザー間の互換性を確保するには、数多くある JavaScript ライブラリのうちの一つを使用してください。</p> -</div> - -<p>さらに詳細を知りたい場合は {{domxref("EventTarget.addEventListener")}} のリファレンスを参照してください。</p> - -<h3 id="HTML_attribute" name="HTML_attribute"><a href="/ja/docs/Web/Guide/HTML/Event_attributes">HTML 属性</a></h3> - -<pre class="brush: html notranslate"><button onclick="alert('Hello world!')"> -</pre> - -<p>HTML 属性に書かれたこの JavaScript コードには、 <code>event</code> 引数を通してイベントオブジェクトが渡されます。<a href="http://dev.w3.org/html5/spec/webappapis.html#the-event-handler-processing-algorithm">返値は HTML の仕様で定義された特別な方法で処理されます</a>。</p> - -<div class="blockIndicator warning"> -<p><strong>警告:</strong> この方法は避けてください。これはマークアップを増加させ、可読性を下げます。コンテンツと振る舞いが正しく分離されておらず、バグの発見が困難になります。</p> -</div> - -<h3 id="DOM_element_properties" name="DOM_element_properties">DOM 要素のプロパティ</h3> - -<pre class="brush: js notranslate">// myButton は button 要素と仮定します -myButton.onclick = function(event){alert('Hello world')} -</pre> - -<p>この関数は 1 つの <code>event</code> 引数を取るように定義できます。<a href="http://dev.w3.org/html5/spec/webappapis.html#the-event-handler-processing-algorithm">返り値は HTML の仕様で定義された特別な方法で処理されます</a>。</p> - -<p>この書き方の問題は、各要素の各イベント毎に 1 つだけしかハンドラーを設定できないことです。</p> - -<h2 id="Accessing_Event_interfaces" name="Accessing_Event_interfaces">Event インターフェイスへのアクセス</h2> - -<p>イベントハンドラーは (DOM 要素や文書、 {{domxref("window")}} オブジェクト等を含めた) 様々なオブジェクトに追加されるでしょう。イベントが発生すると、イベントオブジェクトが生成され順番にイベントリスナーが呼ばれます。</p> - -<p>{{domxref("Event")}} インターフェイスは、イベントハンドラーの内部からアクセス可能で、第 1 引数としてイベントオブジェクトを介して渡されます。以下のシンプルな例は、イベントハンドラーにどのようにイベントオブジェクトが渡され、その中でどのように使われるかを示します。</p> - -<pre class="brush: js notranslate">function print(evt) { - // evt 引数は自動的にイベントオブジェクトに割り当てられます - // console.log と alert の違いに注意してください - console.log('print:', evt) - alert(evt) -} -// どの関数も意味を持つ適切な名前を付けてください -table_el.onclick = print -</pre> - -<h2 id="Subnav">Subnav</h2> - -<ul> - <li><a href="/ja/docs/Web/API/Document_Object_Model">DOM リファレンス</a></li> - <li><a href="/ja/docs/Web/API/Document_Object_Model/Introduction">DOM への導入</a></li> - <li><a href="/ja/docs/Web/API/Document_Object_Model/Events">イベントと DOM</a></li> - <li><a href="/ja/docs/Web/API/Document_Object_Model/Examples">例</a></li> -</ul> |