014.xhtml (1348B)
1 <?xml version="1.0" encoding="utf-8"?> 2 <html xmlns="http://www.w3.org/1999/xhtml"> 3 <head> 4 <title>Drag and drop and scrolling: dropping block element onto canvas inside scrollable container</title> 5 <style type="text/css"> 6 div[draggable] 7 {width:20px; 8 height:20px; 9 background-color:green;} 10 p + div 11 {height:100px; 12 width:100px; 13 overflow:scroll;} 14 canvas 15 {display:block; 16 margin:100px 0 0 100px;} 17 </style> 18 <script type="application/ecmascript"> 19 function paint(color) 20 {var canvas = document.querySelector('canvas'), 21 c = canvas.getContext('2d'); 22 c.fillStyle = color; 23 c.beginPath(); 24 c.moveTo(0,0); 25 c.lineTo(100,0); 26 c.lineTo(100,100); 27 c.lineTo(0,100); 28 c.closePath(); 29 c.fill();} 30 function start(event) 31 {event.dataTransfer.effectAllowed = 'copy'; 32 event.dataTransfer.setData('text/plain', 'green');} 33 </script> 34 </head> 35 <body onload="paint('gray')"> 36 <div draggable="true" ondragstart="start(event)"/> 37 <p>You should be able to drag green box above to the gray canvas in the right-bottom corner of the scrollable container (dragging towards the corner triggers scrolling). Canvas should be repainted to match dropped color.</p> 38 <div> 39 <canvas width="100" height="100" ondragenter="event.preventDefault()" ondragover="return false" ondrop="paint(event.dataTransfer.getData('text/plain'))">Canvas</canvas> 40 </div> 41 </body> 42 </html>