<system.web> <pages> <controls> <add namespace="Microsoft.Web.UI" assembly="Microsoft.Web.Atlas" tagPrefix="atlas"/> <add namespace="Microsoft.Web.UI.Controls" assembly="Microsoft.Web.Atlas" tagPrefix="atlas"/> </controls> </pages> </system.web> |
<atlas:ScriptManager ID="ScriptManager1" runat="server"> <Scripts> <atlas:ScriptReference ScriptName="AtlasUIDragDrop" /> </Scripts> </atlas:ScriptManager> |
<div style="background-color:Red;height:800px;width:600px;"> <div id="draggableDiv" style="height:100px;width:100px;background-color:Blue;"> <div id="handleBar" style="height:20px;width:auto;background-color:Green;"> </div> </div> </div> |
<script type="text/xml-script"> <page xmlns:script="http://schemas.microsoft.com/xml-script/2005"> <components> <control id="draggableDiv"> <behaviors> <floatingBehavior handle="handleBar"/> </behaviors> </control> </components> </page> </script> |
<script type="text/javascript"> function addFloatingBehavior(ctrl, ctrlHandle){ //创建新的漂浮行为对象 var floatingBehavior = new Sys.UI.FloatingBehavior(); //漂浮行为类具有一个Handle属性 floatingBehavior.set_handle(ctrlHandle); //把对象参考值的为Atlas客户端控件 var dragItem = new Sys.UI.Control(ctrl); //从Atlas控件中取得行为集合 //添加我们自己的漂浮行为 dragItem.get_behaviors().add(floatingBehavior); //运行该漂浮行为的内部javascript floatingBehavior.initialize(); } </script> |
<script type="text/javascript"> function pageLoad(){ addFloatingBehavior(document.getElementById('draggableDiv'),document.getElementById('handleBar')); } </script> |
<script type="text/javascript"> function pageLoad(){ addFloatingBehavior($('draggableDiv'),$('handleBar')); } </script> |
function createDraggableDiv() { var panel= document.createElement("div"); panel.style.height="100px"; panel.style.width="100px"; panel.style.backgroundColor="Blue"; var panelHandle = document.createElement("div"); panelHandle.style.height="20px"; panelHandle.style.width="auto"; panelHandle.style.backgroundColor="Green"; panel.appendChild(panelHandle); var target = $('containerDiv').appendChild(panel); addFloatingBehavior(panel, panelHandle); } |
<input type="button" value="Add Floating Div" /> <div id="containerDiv" style="background-color:Purple;height:800px;width:600px;"/> |
<%@ Page Language="C#" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Imperative Drag and Drop II</title> <script type="text/javascript"> function createDraggableDiv() { var panel= document.createElement("div"); panel.style.height="100px"; panel.style.width="100px"; panel.style.backgroundColor="Blue"; var panelHandle = document.createElement("div"); panelHandle.style.height="20px"; panelHandle.style.width="auto"; panelHandle.style.backgroundColor="Green"; panel.appendChild(panelHandle); var target = $('containerDiv').appendChild(panel); addFloatingBehavior(panel, panelHandle); } function addFloatingBehavior(ctrl, ctrlHandle){ var floatingBehavior = new Sys.UI.FloatingBehavior(); floatingBehavior.set_handle(ctrlHandle); var dragItem = new Sys.UI.Control(ctrl); dragItem.get_behaviors().add(floatingBehavior); floatingBehavior.initialize(); } </script> </head> <body> <form id="form1" runat="server"> <atlas:ScriptManager ID="ScriptManager1" runat="server"> <Scripts> <atlas:ScriptReference ScriptName="AtlasUIDragDrop" /> </Scripts> </atlas:ScriptManager> <h2>Imperative Drag and Drop Code with javascript: demonstrate dynamic loading of behaviors</h2> <input type="button" value="Add Floating Div" /> <div id="containerDiv" style="background-color:Purple;height:800px;width:600px;"/> </form> </body> </html> |
Sys.UI.IDragSource = function() { this.get_dataType = Function.abstractMethod; this.get_data = Function.abstractMethod; this.get_dragMode = Function.abstractMethod; this.onDragStart = Function.abstractMethod; this.onDrag = Function.abstractMethod; this.onDragEnd = Function.abstractMethod; } Sys.UI.IDragSource.registerInterface('Sys.UI.IDragSource'); Sys.UI.IDropTarget = function() { this.get_dropTargetElement = Function.abstractMethod; this.canDrop = Function.abstractMethod; this.drop = Function.abstractMethod; this.onDragEnterTarget = Function.abstractMethod; this.onDragLeaveTarget = Function.abstractMethod; this.onDragInTarget = Function.abstractMethod; } Sys.UI.IDropTarget.registerInterface('Sys.UI.IDropTarget'); |
Type.registerNamespace('Custom.UI'); Custom.UI.DropZoneBehavior = function() { Custom.UI.DropZoneBehavior.initializeBase(this); this.initialize = function() { Custom.UI.DropZoneBehavior.callBaseMethod(this, 'initialize'); //把我们自己注册为一个拖放目标. Sys.UI.DragDropManager.registerDropTarget(this); } this.dispose = function() { Custom.UI.DropZoneBehavior.callBaseMethod(this, 'dispose'); } this.getDescriptor = function() { var td = Custom.UI.DropZoneBehavior.callBaseMethod(this, 'getDescriptor'); return td; } //IDropTarget成员. this.get_dropTargetElement = function() { return this.control.element; } this.drop = function(dragMode, type, data) { alert('dropped'); } this.canDrop = function(dragMode, dataType) { return true; } this.onDragEnterTarget = function(dragMode, type, data) {} this.onDragLeaveTarget = function(dragMode, type, data) {} this.onDragInTarget = function(dragMode, type, data) {} } Custom.UI.DropZoneBehavior.registerClass('Custom.UI.DropZoneBehavior', Sys.UI.Behavior, Sys.UI.IDragSource, Sys.UI.IDropTarget, Sys.IDisposable); Sys.TypeDescriptor.addType('script', 'DropZoneBehavior', Custom.UI.DropZoneBehavior); |
<atlas:ScriptManager ID="ScriptManager1" runat="server"> <Scripts> <atlas:ScriptReference ScriptName="AtlasUIDragDrop" /> <atlas:ScriptReference Path="scriptLibrary/DropZoneBehavior.js" /> </Scripts> </atlas:ScriptManager> |
<div style="background-color:Red;height:200px;width:200px;"> <div id="draggableDiv" style="height:100px;width:100px;background-color:Blue;"> <div id="handleBar" style="height:20px;width:auto;background-color:Green;"> </div> </div> </div> <div id="dropZone" style="background-color:cornflowerblue;height:200px;width:200px;"> Drop Zone </div> |
<script type="text/xml-script"> <page xmlns:script="http://schemas.microsoft.com/xml-script/2005"> <components> <control id="dropZone"> <behaviors> <DropZoneBehavior/> </behaviors> </control> <control id="draggableDiv"> <behaviors> <floatingBehavior handle="handleBar"/> </behaviors> </control> </components> </page> </script> |
function addDropZoneBehavior(ctrl){ var dropZone = new Sys.UI.Control(ctrl); var dropZoneBehavior = new Custom.UI.DropZoneBehavior(); dropZone.get_behaviors().add(dropZoneBehavior); dropZoneBehavior.initialize(); } |
<%@ Page Language="C#" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head id="Head1" runat="server"> <title>Imperative Drop Targets</title> <script type="text/javascript"> function addFloatingBehavior(ctrl, ctrlHandle){ var floatingBehavior = new Sys.UI.FloatingBehavior(); floatingBehavior.set_handle(ctrlHandle); var dragItem = new Sys.UI.Control(ctrl); dragItem.get_behaviors().add(floatingBehavior); floatingBehavior.initialize(); } function addDropZoneBehavior(ctrl){ var dropZone = new Sys.UI.Control(ctrl); var dropZoneBehavior = new Custom.UI.DropZoneBehavior(); dropZone.get_behaviors().add(dropZoneBehavior); dropZoneBehavior.initialize(); } function pageLoad(){ addDropZoneBehavior($('dropZone')); addFloatingBehavior($('draggableDiv'),$('handleBar')); } </script> </head> <body> <form id="form1" runat="server"> <atlas:ScriptManager ID="ScriptManager1" runat="server"> <Scripts> <atlas:ScriptReference ScriptName="AtlasUIDragDrop" /> <atlas:ScriptReference Path="scriptLibrary/DropZoneBehavior.js" /> </Scripts> </atlas:ScriptManager> <h2>Imperative Drop Targets with javacript</h2> <div style="background-color:Red;height:200px;width:200px;"> <div id="draggableDiv" style="height:100px;width:100px;background-color:Blue;"> <div id="handleBar" style="height:20px;width:auto;background-color:Green;"> </div> </div> </div> <div id="dropZone" style="background-color:cornflowerblue; height:200px;width:200px;">Drop Zone</div> </form> </body> </html> |
本文出自 “青峰” 博客,转载请与作者联系!