欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

jquery实现拖拽功能(拖拽插件)

程序员文章站 2022-07-15 09:00:43
...
<%@ 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 class="block" id="one">
        <div id="x">x轴</div>
</div>
<div class="block" id="two">
        <div id="y">y轴</div>
</div>
<div class="block" id="three">
        <div id="parent">父元素</div>
</div>-->

<div class="draggable red">draggable red</div>
<div class="draggable green">draggable green</div>
<div id="draggable-accept" class="draggable">
draggable


</div>
</body>
</html>