- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有以下代码:
jQuery(document).ready(function(){
$('.dragThis').draggable({
stop: function(event, ui) {
var teste = $("#teste").offset();
var pos = ui.helper.offset();
$("#posX").val(pos.left - teste.left);
$("#posY").val(pos.top - teste.top);
var posX = $("#posX").val();
var posY = $("#posY").val();
$('#X').val(posX);
$('#Y').val(posY);
},
containment: "parent",
cursor: "move",
});
$('#dropHere').droppable({
accept: '.dragThis',
over: function(){
$(this).animate({
'border-width': '5px',
'border-color': '#0f0'
}, 200);
$('.dragThis').draggable('option', 'containment', $(this));
}
});
在 home.php 中:
<div id="mydivcanvas">
<div class="dragThis displayes">
content 1
</div>
<div class="dragThis displayes">
content 2
</div>
<div class="dragThis displayes">
content 3
</div>
<ul class="dragThis displayes">
<li>
<span>
<img id="imagem_teste" src="../uploads/imagens/.jpg" style="z-index:-1" >
</span>
</li>
</ul>
<div id="dropHere"></div>
</div>
<input type="button" id="save_voucher" value="Save Voucher" onclick="capture();" />
我试图通过单击“保存凭证”仅获取已拖入 #dropHere
的内容div 留在类 .displayed
但是#dropHere
外面的是什么应该改为类 .displayed
至 .displano
单击“保存凭证”后,只应显示已拖放到此处的内容
感谢您的帮助
最佳答案
首先,我会说您的标记无效,因为您已将相同的 ID 分配给多个元素。根据标准,ID 必须唯一地分配给每个元素。
因此,解决方案是改为类:
<div class="dragThis displayes">
content 1
</div>
并更改js:
$('.dragThis').draggable({
// other code as is
});
你需要使用drop:fn
回调:
$('#dropHere').droppable({
accept: '.dragThis', // <----change to class selector
over: function(){
$(this).animate({
'border-width': '5px',
'border-color': '#0f0'
}, 200);
$('.dragThis').draggable('option', 'containment', $(this));
},
drop:function(event, ui){
$(ui.draggable).toggleClass('displayes displano'); //<---change the css class here.
$(ui.draggable).siblings('.dragThis').hide(); // hide others as they are siblings
}
});
在此处查看演示:
$(function() {
$( "#draggable" ).draggable();
$( "#droppable" ).droppable({
drop: function( event, ui ) {
$(ui.draggable).addClass('active');
}
});
});
#draggable { width: 100px; height: 100px; padding: 0.5em; float: left; margin: 10px 10px 10px 0; }
#droppable { width: 150px; height: 150px; padding: 0.5em; float: left; margin: 10px; }
.active{background:red !important; color:white !important;}
<link rel="stylesheet" href="https://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<script src="https://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<div id="draggable" class="ui-widget-content">
<p>Drag me to my target</p>
</div>
<div id="droppable" class="ui-widget-header">
<p>Drop here</p>
</div>
关于jquery - 如何在 droppable 中拖动后更改类 css,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34512039/
作为 JavaScript/JQuery 新手,我在弄清楚如何实现将多个可放置对象的放置函数注册到一个函数时遇到了一些问题,例如: $('#droppableLW').droppable({
我正在制作一个涉及可排序的用户界面,其中有可放置的列表项。这是它的一个 fiddle : http://jsfiddle.net/NRkwx/ 问题是这样的:当您开始排序并移动列表项时,可放置项也会移
如果屏幕上的可拖动图像被放入拖放区(也是图像,而不是 var counter = 0;),我正在尝试增加计数器的值(div)。 $( "#goldbag" ).draggable({ revert:
使用 JQuery draggable/droppables 允许我将 div 从一个容器拖到另一个容器并将它们作为子项插入到容器中。我可以在 HTML 中看到移动,但在屏幕上,当我将可拖动对象释放到
以下 jsbin 最好地解释了不触发 over 事件的情况。 . 执行以下操作: 将可拖动对象放置在内部可放置对象(蓝色)上。 将可拖动对象拖到外部可放置对象(红色)上,它应该将其背景颜色更改为绿色,
我正在尝试在学习应用程序中实现拖放功能。 这很好用,将一个项目放到可放置区域就像它应该的那样工作。 // Adding drop function to each category j
我正在使用 jquery ui 拖放。 如果可放置 div ( #dropContainer ) 的 css 位置为相对/绝对/固定,则放置的元素不会放置在我的鼠标指针上。 If I remove
一个小问题,希望有一个简单的答案,我正在使用 jQuery 可拖动和可放置的项目将项目放入停靠栏。使用以下代码进行转换。 $("#dock").droppable({ drop
我对以下事件有看法。 View ID 是“folders-block”。 我的元素是 View 是这样的: 下面是主干中的事件
如何动态创建 div 并将其放入可放置的 div 中? 这是实际的代码。 jQuery UI Droppable - Default functionality
我有一个包含不同可拖动元素的容器,并且有一些“目标”div 的列表,用户可以在其中放置可拖动元素。 示例:想象一下,您有一个“标签”列表(房屋、计算机、汽车等)和一些作为目标的文档列表(所有文档都是
$(".LWdrop").droppable({ accept: ".LW", drop: function(event, ui){
我对 jQuery 有点陌生,希望有人能帮助我。 我试图在删除 (li) 后将一个元素 (li) 更改为另一个元素 (div)。 示例代码: $("#inputEl>li").draggable({
我正在尝试使用 jquery ui Draggable/droppable 拖放到文本区域中。我将文本区域设置为可放置。我能够在放置发生时触发事件,但我不知道如何准确确定“放置”发生在文本区域中的哪个
当我拖放到某个 div 时,我想获得拖动的 id Drag drop here!! JQUER
我需要能够获取设置为可拖动的元素,并将该元素物理移动到容器中,而不是像当前功能那样仅覆盖它。 例如: $(function () { $(".image").dragg
我正在制作一个应用程序,它使用一个可放置的 div 和一些可拖动的 div 。如何使 droppable 不接受多个可拖动 div?我用 Google 搜索了,但没有找到任何解决方法。 我想到了一个解
我有一个 div,我可以将其拖动到其他 div,并且它工作正常。 但使用 helper: 'clone' 时,可以拖动 div,但 droppable 不起作用。 你知道如何解决这个问题吗? jque
那么如何限制 droppable 仅包含完整的draggable? 看看这个例子.. http://jsfiddle.net/jWNkh/1/ ..尝试将可拖动对象拖动到可放置对象,您将看到可放置对象
我正在为调查创建问题类型。 我正在使用下面的jsfiddle http://jsfiddle.net/hP3jc/ 我需要一个计数器或类似的东西,让我知道有多少红色 block 被丢弃到底部灰色 bl
我是一名优秀的程序员,十分优秀!