jquery实现拖拽功能(拖拽插件)
<%@ page language="java" import="java.util.*" pageEncoding="GB18030"%>
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title></title>
<style>
<font color="magenta">.block{ width:200px; height:200px; background:#CCC; border:1px solid #FF0; margin-top:10px; margin-left:100px;}
#x,#y{width:50px; height:50px; border:1px solid #F00;}
#parent{width:100px; height:100px; border:1px solid #090;}
.draggable{width:300px; height:300px; border:1px solid #333; margin-top:10px; text-align:center; vertical-align:middle;}
.red, .green{width:100px; height:100px; border:1px solid red; margin-top:10px;}
.green{ border:1px solid green;}</font>
</style>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script type="text/javascript" src="../js/jquery-ui.js"></script>
<script type="text/javascript">
$(function(){
//draggable的用法
/* for(var i=0;i<3;i++){
$(document.body).append($("<div class='block'>"+i.toString()+"</div>"));
}
$(".block").draggable();*/
//x、y轴拖拽
/*$("#x").draggable({axis:"x"});
$("#y").draggable({containment:"parent",axis:"y"});
$("#parent").draggable({containment:"parent"});
*/
//拖入购物车
$(".draggable").draggable({helper:"clone"});
$("#draggable-accept").droppable({
accept:function(draggable){
return $(draggable).hasClass("green");
},
drop:function(){
$(this).append($("<div></div>")).html("drop!");
}
});
});
</script>
</head>
<body>
<!--<div id="one">
<div id="x">x轴</div>
</div>
<div id="two">
<div id="y">y轴</div>
</div>
<div id="three">
<div id="parent">父元素</div>
</div>-->
<div class="draggable">
draggable
</div>
</body>
</html>