Javascript 在jquery拖动事件中检测悬停
我使用的是jQueryUI拖放效果,当我拖动元素时,我需要执行一段代码来检测元素是否悬停 更新:现场示例: 这是我的拖动代码:Javascript 在jquery拖动事件中检测悬停,javascript,jquery,drag-and-drop,Javascript,Jquery,Drag And Drop,我使用的是jQueryUI拖放效果,当我拖动元素时,我需要执行一段代码来检测元素是否悬停 更新:现场示例: 这是我的拖动代码: <script type="text/javascript"> $(function(){ $('.list-disc').sortable({ connectWith: '.list-disc', drag: function(event, ui){ $(".prof-name
<script type="text/javascript">
$(function(){
$('.list-disc').sortable({
connectWith: '.list-disc',
drag: function(event, ui){
$(".prof-name").hover(function(event) {
var $obj = event.target;
if (!timeoutId) {
timeoutId = window.setTimeout(function() {
timeoutId = null;
$($obj).next().slideToggle();
}, 2000);
}
},
function (event) {
if (timeoutId) {
window.clearTimeout(timeoutId);
timeoutId = null;
}
else {
$(event.target).next().slideToggle();
}
});
},
start: function (event, ui){
//SomeCode
},
stop: function (event, ui){
//SomeCode
}
})
</script>
试试这个:
$( ".list-disc").sortable({
over: function( event, ui ) { // $(this) will be the current hovered element }
});
你能发布一个JSFIDLE演示吗?我们会更容易帮助你wau@Ron当然,更新了codepen live示例。您确定示例正确吗?我在示例中没有看到任何可排序的函数这不是您应该如何使用它。。您应该检查over`if$.prof name==$this'的内部,然后执行您想要的操作,否则它不在该元素上。我还建议您使用console.log$this,并在悬停时查看它所在的元素
$( ".list-disc").sortable({
over: function( event, ui ) { // $(this) will be the current hovered element }
});