Saturday, February 11, 2012

Drag and drop in HTML 5

Drag and drop element 
Drag and drop is very much necessary when we want to drag some element and drop into other element. The below code will not work in opera browser.

<style type="text/css">
#mydiv {width:350px;height:70px;padding:10px;border:1px solid #aaaaaa;}
<script type="text/javascript">
function allowDrop(ev)

function drag(ev)

function drop(ev)
var data=ev.dataTransfer.getData("Text");;
<p>Drag the image into the rectangle:</p>
<div id="mydiv" ondrop="drop(event)" ondragover="allowDrop(event)"></div>
<br />
<img id="drag1" src="yourimage.gif" draggable="true" ondragstart="drag(event)" width="400" height="100" />

Here one rectangular box will come and try to drag your picture within rectangular window. It may not work if your browser do not support HTML 5 fully.
The draggable=”true” make the image draggable.

No comments:

Post a Comment