| 目次 |
|---|
|
・ドラッグアンドドロップの原理 ・移動処理 ・マウスボタンを放す処理 |
<div id="block" style="background-color: red; width: 32px; height: 32px;"></div>
$("#block").mousedown(function(){
$(window).mousemove(function(){
// 移動処理
});
});
$("#block").mousedown(function(){
$(window.document).mousemove(function(e){
$("#block").css({
position: "absolute",
top: e.pageY,
left: e.pageX
});
});
});
$("#block2").mousedown(function(){
$(window.document).mousemove(function(e){
$("#block2").css({
position: "absolute",
top: e.pageY,
left: e.pageX
});
});
});
$(window.document).mouseup(function(){
$(window.document).unbind("mousemove");
});