I use html5 to implement 'drag and drop' http://www.w3schools.com/html/html5_draganddrop.asp .
But my drop-down boxes are quite a lot and cannot be displayed in the displayed area of ββthe window. Therefore, when I drag an item to (for example.) The bottom drop-down box of a window that is out of the displayed range, how do I automatically scroll the window?
Like the following webpage, where I want to drag and drop the image and drop it onto the bottom rectangle (fifth), which goes beyond the displayed area. When I drag the image to the end of the window, how do I automatically scroll the window to the end?
<!DOCTYPE HTML> <html> <head> <style type="text/css"> #div1,#div2,#div3,#div4,#div5 { width:350px; height:200px; padding:10px; border:1px solid #aaaaaa; } </style> <script> function allowDrop(ev) { ev.preventDefault(); } function drag(ev) { ev.dataTransfer.setData("Text",ev.target.id); } function drop(ev) { ev.preventDefault(); var data = ev.dataTransfer.getData("Text"); ev.target.innerHTML += data+"droppedHere"+"<br/>"; } </script> </head> <body> <p>Drag the W3Schools image into the rectangle:</p> <img id="drag1" src="http://www.w3schools.com/html/img_logo.gif" draggable="true" ondragstart="drag(event)" width="336" height="69" /> <div id="div1" ondrop="drop(event)" ondragover="allowDrop(event)"></div> <div id="div2" ondrop="drop(event)" ondragover="allowDrop(event)"></div> <div id="div3" ondrop="drop(event)" ondragover="allowDrop(event)"></div> <div id="div4" ondrop="drop(event)" ondragover="allowDrop(event)"></div> <div id="div5" ondrop="drop(event)" ondragover="allowDrop(event)"></div> <br> </body> </html>
(You can copy the code above into the left column http://www.w3schools.com/html/tryit.asp?filename=tryhtml5_draganddrop and check the result on the right. I want to show that in jsfiddle, but I donβt know why the code does not work there )
I noticed that Chrome can do this automatically, but not for other browsers like safari.
I also found related solutions, such as "scroll functions" or "mouse detection from a window." But I just can't get what I want based on their codes. Appreciate this if someone can provide a more detailed / full version of the solution.
source share