コードをインラインでコメントします。
//all variables ext,spot,box are defined, not "false" and not 0 and not null
if (ext && spot && box) {
/* We assign onmousemove event handler to the function, in javascript functions are vars
* function declared like `function function_name(param) {}` go to global scope,
* and almost equal to 'function_name=function(param ) {}'
* var local scope use `var function_name=function(param) {}`
*/
document.getElementById('text-shadow-box').onmousemove = onMouseMove;
/* add here is another example, you attach ontouchmove anonymous function,
* anonymous function BEGIN NEXT LINE */
document.getElementById('text-shadow-box').ontouchmove = function (e) {
// e here it is event object, which passed to handler function as argument
//it is jquery call, mean do not start other event handlers after this line
e.preventDefault(); e.stopPropagation();
/* call function inMousemove, declared somewhere else
The "{
clientX: e.touches[0].clientX,
clientY: e.touches[0].clientY
}" here is object having two properties - clientX and clientY */
onMouseMove({
clientX: e.touches[0].clientX,
clientY: e.touches[0].clientY
});
/* anonymous function END NEXT LINE */
};
ontouchmove およびその他のタッチスクリーン イベントは
ここで説明されていますが、タッチは画面へのタッチを処理するオブジェクトである
ように見え ます。タッチスクリーン デバイスがないため、確認できませんが、タッチされた要素には 2 つの方法でアクセスできるよう
e.touches.item(n)
です。 doc) および 2 番目 - e.touches を array として使用する場合
e.touches[n]
。n==0 は、w3c 仕様から理解できるように、最初に触れた要素を意味します。
event.stopPropagation()
説明: イベントが DOM ツリーをバブリングしないようにして、親ハンドラーにイベントが通知されないようにします。
event.preventDefault()
説明: このメソッドが呼び出された場合、イベントのデフォルト アクションはトリガーされません。
したがってevent.stopPropagation()
、その要素の親がそのイベントを受け取るのを防ぎます (2 つの折りたたまれた div があり、両方にイベント リスナーがあるとします)。
デフォルトのアクションをevent.preventDefault()
防ぎます(<a href="test.html"></a>
onclickイベントハンドラーがあるとします。したがって、ブラウザーにtest.htmlをロードさせるアクションを防ぐのは良いことです