All Components

Drag and Drop / AngularJS

{{ dropTargetText }}

HTML5/JavaScript 源码

<!DOCTYPE html>
<html>
 <head> 
  <title>AngularJS</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/angular.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" ng-app="KendoDemos"> 
   <div ng-controller="MyCtrl"> 
    <div class="demo-section k-content"> 
     <div id="droptarget" kendo-droptarget="" k-dragenter="onDragEnter" k-dragleave="onDragLeave" k-drop="onDrop" class="k-header">
      {{ dropTargetText }}
     </div> 
     <div class="{{ draggableCLass }}" id="draggable" kendo-draggable="" k-hint="draggableHint" k-dragstart="onDragStart" k-dragend="onDragEnd"></div> 
    </div> 
   </div> 
   <script>
        angular.module("KendoDemos", [ "kendo.directives" ])
            .controller("MyCtrl", function($scope){
                $scope.dropTargetText = "Drag the small circle here.";
    
                $scope.draggableHint = function() {
                    return $("#draggable").clone();
                }
    
                $scope.onDragEnd = function() {
                    var draggable = $("#draggable");
    
                    if (!draggable.data("kendoDraggable").dropped) {
                        // drag ended outside of any droptarget
                        $scope.dropTargetText = "Try again!";
                    }
    
                    draggable.removeClass("hollow");
                }
    
                $scope.onDragStart = function() {
                    $scope.$apply(function() {
                        $scope.draggableClass = "hollow";
                        $scope.dropTargetText = "Drop here.";
                    });
                }
    
                $scope.onDragEnter = function(e) {
                    $scope.$apply(function() {
                        $scope.dropTargetText = "Now drop...";
                    });
                }
    
                $scope.onDragLeave = function(e) {
                    $scope.$apply(function() {
                        $scope.dropTargetText = "Drop here.";
                    });
                }
    
                $scope.onDrop = function(e) {
                    $scope.$apply(function() {
                        $scope.dropTargetText = "You did great!";
                        $scope.draggableClass = "";
                    });
                }
            })
</script> 
   <style>
    #draggable {
        cursor: move;
        position: absolute;
        top: 260px;
        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);
    }
    .painted {
        background-color: #03a9f4;
        color: #fff;
    }
    
    #draggable.hollow
    {
        cursor: default;
        background: #ececec;
    }
    
    #droptarget
    {
        height: 200px;
        width: 200px;
        font-size: 14px;
        border-radius: 50%;
        text-align: center;
        line-height: 200px;
        margin: 0 auto;
        cursor: default;
        border: 1px solid #999;
    }

    .demo-section
    {
        height: 300px;
        position: relative;
    }
</style> 
  </div>   
 </body>
</html>