Kendo Draggable allows the DOM element to move around the HTML body using the mouse or finger for touch device.
This blog say’s how to implement the kendo draggable and moving the div element around the HTML body using jQuery.
Coding
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8"/>
- <title>Kendo UI Snippet</title>
- <link rel="stylesheet" href="http://kendo.cdn.telerik.com/2016.2.607/styles/kendo.common.min.css"/>
- <link rel="stylesheet" href="http://kendo.cdn.telerik.com/2016.2.607/styles/kendo.rtl.min.css"/>
- <link rel="stylesheet" href="http://kendo.cdn.telerik.com/2016.2.607/styles/kendo.silver.min.css"/>
- <link rel="stylesheet" href="http://kendo.cdn.telerik.com/2016.2.607/styles/kendo.mobile.all.min.css"/>
- <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
- <script src="http://kendo.cdn.telerik.com/2016.2.607/js/kendo.all.min.js"></script>
- </head>
- <body>
- <body style="padding: 0; margin: 0; ">
- <div id="drop" style="position: absolute;height:100%;width:100%">
- <div class="draggable">
- Please Move me....
- </div>
- </div>
- </body>
- <script>
- $('.draggable').kendoDraggable({
- hint : function (original) {
- return original.clone().addClass("drag-clone");
- },
- dragstart: function (e) {
- $(e.target).addClass("drag-hide");
- }
- });
- $('body').kendoDropTarget({
- drop: function (e) {
- var pos = $(".drag-clone").offset();
- $(e.draggable.currentTarget)
- .removeClass("drag-hide")
- .offset(pos);
- }
- })
- </script>
- <style>
- .draggable {
- position: absolute;
- background: orange;
- width: 200px;
- height: 100px;
- vertical-align: middle;
- }
- .drag-hide {
- display: none;
- }
- .drag-clone {
- background: orange;
- }
- </style>
- </body>
- </html>
First we need to initialize the kendo draggable for the div (In my case I have used div class name as a selector)
The drop event in the kendoDropTarget is fired when the div is placed in new position.
Result
Initial Position
After Moving
I hope you enjoyed this blog. Your valuable feedback, question, or comments about this blog are always welcomed.