在web应用程序ASP.net中拖放和移动图像
Drag, Drop and move Image within web application ASP.net
我的要求是
- 从列表中拖动图像并将其放入新的Div(ImgContainer)中。原始图像应仍在图像列表中
- 丢弃的图像应该能够在Div(ImgContainer)中移动
帮我做这个。这就是我所做的。我使用了ASP.net和1.9.2(Legacy,用于jQuery1.6+
<script>
$(function () {
$("#Item1").draggable({
containment: "#ImgContainer",
cursor: 'move',
appendTo: "#ImgContainer",
helper: "clone"
});
});
$(function () {
ImgContainer.droppable({
accept: "#gallery > li",
activeClass: "ui-state-highlight",
drop: function (event, ui) {
$("img").clone(ui.draggable.clone()).appendTo(this);
}
});
});
</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<form id="form1" runat="server">
<div class="ui-widget ui-helper-clearfix">
<ul id="gallery" class="gallery ui-helper-reset ui-helper-clearfix" style="width:400px; float:left !important">
<li class="ui-widget-content ui-corner-tr">
<img id="Item1" src="https://cdn4.iconfinder.com/data/icons/pictype-free-vector-icons/16/home-128.png" alt="The peaks of High Tatras" />
</li>
</ul>
<br />
<div id="ImgContainer" class="ui-widget-content ui-state-default" style="width:600px; height:500px" ondrop="drop(event)">
<h4 class="ui-widget-header"><span class="ui-icon ui-icon-ImgContainer">ImgContainer</span></h4>
</div>
</div>
</form>
您的代码很好,除了5件事:
-
draggble/doppable是jquery UI方法。先把它也包括在内。
-
如果在一个普通的javascript项
ImgContainer
上调用droptable,则需要首先使用jQuery选择它:$("#ImgContainer")
-
您在图像中调用draggable,而不是在列表项上,但您只接受droptable中的列表项。将
> img
添加到accept属性。 -
容器中的
ondrop
属性覆盖jquery dropapble drop。去掉它。 -
dropepd项目需要再次声明为可拖动,因为它们是原始的克隆
$(function () {
$("#Item1").draggable({
containment: "#ImgContainer",
cursor: 'move',
appendTo: "#ImgContainer",
helper: "clone"
});
});
$(function () {
$("#ImgContainer").droppable({
accept: "#gallery > li > img, #ImgContainer > img",
activeClass: "ui-state-highlight",
drop: function (event, ui) {
ui.draggable.clone().appendTo(this).draggable({
containment: "#ImgContainer",
cursor: 'move',
appendTo: "#ImgContainer"
});;
}
});
});
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.3/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.3/jquery-ui.js"></script>
<form id="form1" runat="server">
<div class="ui-widget ui-helper-clearfix">
<ul id="gallery" class="gallery ui-helper-reset ui-helper-clearfix" style="width:400px; float:left !important">
<li class="ui-widget-content ui-corner-tr">
<img id="Item1" src="https://cdn4.iconfinder.com/data/icons/pictype-free-vector-icons/16/home-128.png" alt="The peaks of High Tatras" />
</li>
</ul>
<br />
<div id="ImgContainer" class="ui-widget-content ui-state-default" style="width:600px; height:500px">
<h4 class="ui-widget-header"><span class="ui-icon ui-icon-ImgContainer">ImgContainer</span></h4>
</div>
</div>
</form>
我可以解决我的问题。谢谢大家,这是的解决方案
$(function () {
$("#ImgContainer").droppable({
accept: '.drag',
drop: function (event, ui) {
var $clone = ui.helper.clone();
if (!$clone.is('.insideContainer')) {
$(this).append($clone.addClass('insideContainer').draggable({
containment: '#ImgContainer'
}));
}
}
});
$(".drag").draggable({
helper: 'clone'
});
});
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.3/themes/smoothness/jquery-ui.css"/>
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.3/jquery-ui.js"></script>
<div class="ui-widget ui-helper-clearfix" style="float:left; background-color:white; height:500px; width:250px !important">
<ul id="gallery" class="gallery ui-helper-reset ui-helper-clearfix" style="width:250px; float:left !important">
<li class="ui-widget-content ui-corner-tr">
<img id="Item1" class="drag" src="http://50.198.27.57:8081/imagesDoc/IPD/1.jpg" style="width:100px; height:100px !important;" alt="The peaks of High Tatras" />
</li>
</ul>
</div>
<div id="ImgContainer" style="height:300px; width:300px; float:right; background-color:silver !important">
</div>
相关文章:
- EaseJS拖放;放下(动画CC)电影剪辑的鼠标坐标
- 为什么HTML5拖放的目标是孩子?(可排序列表)
- HTML/CSS-用于拖放的全页面覆盖
- Rubaxa可与聚合物进行排序/拖放不起作用,具体取决于显示器:
- dblclick事件是在jquery拖放后触发的
- 无法进行拖放以使用本地存储
- 如何使用Java脚本创建提交按钮's的拖放功能
- Chrome原生拖放相对容器并不能正确渲染重影
- 在web应用程序ASP.net中拖放和移动图像
- 重新拖放库是否支持移动设备
- HTML - 如何在固定上下文中在移动设备上拖放
- 拖放元素可以移动 x 但不能移动 y
- 哪一个更适合拖放调整大小移动
- jQuery拖放时移动
- 如何使拖放列表复制而不是移动列表项
- 在移动设备上拖放使用一些代码来翻译事件(包括代码),但正常事件不起作用
- 在使用.css移动一个对象后,重置所有可放物品以允许可拖放物品
- 拖放表-将单元格移动到不同的列
- 拖放表单/上下移动表单
- 当将其他可排序项移动到可排序项上时,如何使可排序项表现得像可拖放项