この記事では、JSがさまざまなブラウザと互換性のある高度なドラッグ方法について説明します。次のように、参照のために共有してください。
<!doctype html public " - // w3c // dtd html 4.01 // en" "http://www.w3.org/tr/html4/strict.dtd"> <html>ドラッグ</title> <style> #tobedraged {width:100px;高さ:100px;ラインハイト:100px;境界線:1px固体赤;位置:絶対;テキストアライグ:センター;フォントファミリー:arial、helvetica、sans-serif;カーソル:移動; } </style> <script type = "text/javascript"> window.onload = function(){dodrag(); } function dodrag(){var div = document.getElementById( "tobedraged"); var posx; var posy; div.onmousedown = function(e){var e = e || window.event; if(div.setcapture){div.setcapture(); } posx = e.clientx -parseint(div.offsetLeft); posy = e.clienty -parseint(div.offsettop); document.onmousemove = function(ev){var ev = ev || window.event; // if is is if(ev.setcapture){} div.style.left =(ev.clientx -posx)+"px"; div.style.top =(ev.clienty -posy)+"px"; } document.onmouseup = function(){document.onmousemove = null; document.onmouseup = null; if(div.releasecapture){div.releasecapture(); }}}}} </script> </head> <body> <div id = "tobedraged">あなたは私をドラッグします!</div> </body> </html>JavaScript関連のコンテンツの詳細については、このサイトのトピックをご覧ください:「JavaScriptの切り替え効果とテクニックの要約」、「JavaScript検索アルゴリズムスキルの要約」、「JavaScriptアニメーション効果とテクニックの概要」、「Javascriptエラー、および「Javascriptデータ構造」の概要」の概要の要約の要約をご覧ください。 JavaScriptトラバーサルアルゴリズムとテクニック」、および「JavaScriptの数学的操作の使用法の要約」
この記事がみんなのJavaScriptプログラミングに役立つことを願っています。