Este artigo descreve o método avançado de arrasto que JS implementa compatíveis com vários navegadores. Compartilhe -o para sua referência, como segue:
<! Docttype html public "-// w3c // dtd html 4.01 // pt" "http://www.w3.org/tr/html4/strict.dtd"> <html> <head> <meta http-equiv = "Chareset-linent"> arraste </title> <style> #tobedraged {width: 100px; Altura: 100px; altura da linha: 100px; borda: 1px vermelho sólido; Posição: Absoluto; Alinhamento de texto: centro; Font-Family: Arial, Helvetica, Sans-Serif; Cursor: Mova; } </style> <script type = "text/javascript"> window.onload = function () {Dodrag (); } função Dodrag () {var div = document.getElementById ("tabedraged"); 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; // se for ie 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> </ad Head> <body> <div id = "tabedraged"> você me arrasta! </div> </body> </html>For more information about JavaScript related content, please check out the topics of this site: "Summary of JavaScript switching effects and techniques", "Summary of JavaScript search algorithm skills", "Summary of JavaScript animation effects and techniques", "Summary of JavaScript errors and debugging techniques", "Summary of JavaScript data structures and algorithm skills", "Summary of Javascript Algoritmos e Técnicas de Traversal "e" Resumo do Uso do Javascript Mathematic Operations "
Espero que este artigo seja útil para a programação JavaScript de todos.