All Components

Drag and Drop / Area

Drag the small circle here ...
... Or here.

HTML5/JavaScript 源码

<!DOCTYPE html>
<html>
 <head> 
  <title>Area</title> 
  <meta charset="utf-8"> 
  <link href="../content/shared/styles/examples-offline.css" rel="stylesheet"> 
  <link href="../../styles/kendo.common.min.css" rel="stylesheet"> 
  <link href="../../styles/kendo.rtl.min.css" rel="stylesheet"> 
  <link href="../../styles/kendo.default.min.css" rel="stylesheet"> 
  <link href="../../styles/kendo.dataviz.min.css" rel="stylesheet"> 
  <link href="../../styles/kendo.dataviz.default.min.css" rel="stylesheet"> 
  <script src="../../js/jquery.min.js"></script> 
  <script src="../../js/kendo.all.min.js"></script> 
  <script src="../content/shared/js/console.js"></script> 
  <script>
        
    </script> 
 </head> 
 <body> 
  <a class="offline-button" href="../index.html">Back</a> 
  <div id="example"> 
   <div class="demo-section k-content"> 
    <div id="droptarget"> 
     <div class="test1">
      Drag the small circle here ...
     </div> 
     <div class="test2">
      ... Or here.
     </div> 
    </div> 
    <div id="draggable"></div> 
   </div> 
   <script>
        function draggableOnDragStart(e) {
            $("#draggable").addClass("hollow");
            $("#droptarget").html("<div class='test1'>(Drop here)</div><div class='test2'>(Drop here)</div>");
        }

        function droptargetOnDragEnter(e) {
            $(e.dropTarget).text("Now you can drop it.");
        }

        function droptargetOnDragLeave(e) {
            $(e.dropTarget).text("(Drop here)");
        }

        function droptargetOnDrop(e) {
            $(e.dropTarget).text("You did great!");
            $("#draggable").removeClass("hollow");
        }

        function draggableOnDragEnd(e) {
            var draggable = $("#draggable");

            if (!draggable.data("kendoDraggable").dropped) {
                // drag ended outside of any droptarget
                $("#droptarget").html("<div class='test1'>(Try again)</div><div class='test2'>(Try again)</div>");
            }

            draggable.removeClass("hollow");
        }

        $(document).ready(function() {
            $("#draggable").kendoDraggable({
                hint: function() {
                    return $("#draggable").clone();
                },
                dragstart: draggableOnDragStart,
                dragend: draggableOnDragEnd
            });

            $("#droptarget").kendoDropTargetArea({
                filter: ".test1, .test2",
                dragenter: droptargetOnDragEnter,
                dragleave: droptargetOnDragLeave,
                drop: droptargetOnDrop
            });
        });
    </script> 
   <style>
        .demo-section {
            padding-top: 100px;
            position: relative;
        }
        
        #draggable {
            cursor: move;
            position: absolute;
            top: 30px;
            left: 50%;
            margin-left: -28px;
            width: 56px;
            height: 56px;
            border-radius: 50%;
            background-color: #03a9f4;
            box-shadow: 0 3px 10px rgba(0, 0, 0, 0.23), 0 3px 10px rgba(0, 0, 0, 0.16);
        }

        #droptarget {
            padding: 20px;
            cursor: default;
            vertical-align: middle;
            text-align: center;
            border: 2px dotted #ccc;
        }

        .test1,
        .test2 {
            vertical-align: middle;
            display: inline-block;
            width: 100px;
            height: 100px;
            line-height: 1.5em;
            margin: 10px;
            padding: 20px;
            font-size: 14px;
            font-weight: normal;
            color: #fff;
        }
        .test1 {
            background-color: #3f51b5;
        }
        .test2 {
            background-color: #ee6f0b;
        }

        *+html .test1,
        *+html .test2 {
            margin-top: 50px;
            display: inline;
            zoom: 1;
        }
    </style> 
  </div>   
 </body>
</html>