简体   繁体   English

如何检测元素是否在另一个元素之上

[英]How to detect if the element is on top of another element

I want to do the drag and drop action in my case. 我想在我的情况下执行拖放操作。

I want to apply droppable in one of my elements so when the dragged element drop in the droppable element, the second element will add another class. 我想在我的一个元素中应用droppable,因此当拖动的元素放入droppable元素时,第二个元素将添加另一个类。

Html HTML

<div id='drag'>
   <img src='http://i60.tinypic.com/1191gxt.jpg' />
   <img src='http://i60.tinypic.com/1191gxt2.jpg' />
</div>

<div id ='drop'>
   <img src='object.jpg'/>
</div>

js js

$('#drag').draggable();
$('#drop').droppable({
            drop: function(event, ui){
              $(this).addClass( "ui-state-highlight" )
            }
        })

My codes don't seem to work. 我的代码似乎无效。 Can anyone help me what happened? 谁能帮我发生什么事情? Thanks a lot! 非常感谢!

Checked your code and it's working: jsfiddle 检查您的代码,它是否正常工作: jsfiddle

Answer : Check if your dependencies (jQuery, jQuery UI) are being loaded and the script is called after the document is loaded. :检查是否已加载您的依赖项(jQuery,jQuery UI),并在加载文档后调用脚本。 Also make sure the image on drop area exists or at least dimensions of #drop are set. 还要确保放置区域上的图像存在或至少设置了#drop尺寸。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM