Skip to content

Instantly share code, notes, and snippets.

@wallin
Created September 17, 2011 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wallin/1223979 to your computer and use it in GitHub Desktop.
Save wallin/1223979 to your computer and use it in GitHub Desktop.
Multiple drag n' drop for touch
<html>
<head>
<meta charset=utf-8 />
<title>Drag n' drop touch demo - sewa.se</title>
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; minimum-scale=1.0; user-scalable=0;" />
<script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<style type="text/css">
.draggable {
position: absolute;
left: 30px;
top: 30px;
width: 60px;
height: 60px;
margin-left: -30px;
margin-top: -30px;
color: #FFF;
font: bold 16px Helvetica,Arial,Sans-serif;
text-align: center;
background-color: #ABF;
border: 3px solid #669;
}
</style>
</head>
<body>
<div class="draggable">Drag me!</div>
<div class="draggable">Drag me!</div>
</body>
<script type="text/javascript">
var moveMe = function(e) {
e.preventDefault();
var orig = e.originalEvent;
$(this).css({
top: orig.changedTouches[0].pageY,
left: orig.changedTouches[0].pageX
});
};
$(".draggable").bind("touchstart touchmove", moveMe);
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment