gpt4 book ai didi

javascript - 当拖动子元素时使元素可拖动

转载 作者:行者123 更新时间:2023-11-28 05:43:22 25 4
gpt4 key购买 nike

我有多个以编程方式创建的跨度元素,其外观和行为类似于窗口。每个元素的顶部都有一个标题栏。我正在尝试使用 jQuery UI 获取它,以便通过或仅当鼠标位于子标题元素上方时才激活可拖动性,这可能吗?

最佳答案

这是可能的。当鼠标按住子元素时,使父元素可拖动,然后当鼠标意识到时,再次使其不可拖动。

 // The parent element
var $aa = $("#aa"),
// The child element
$bb = $("#bb");

// When the mouse is down
$bb.mousedown(function() {
// Drag the element
$aa.draggable();
});

// When the mouse realizes
$bb.mouseup(function() {
// Don't drag the element
$aa.draggable('destroy');
});
<script src="https://code.jquery.com/jquery-1.11.3.js"></script>
<script src="https://code.jquery.com/ui/1.11.3/jquery-ui.min.js" integrity="sha256-xI/qyl9vpwWFOXz7+x/9WkG5j/SVnSw21viy8fWwbeE=" crossorigin="anonymous"></script>

<div id="aa">
---
<div id="bb">Push me</div>
</div>

无论如何,随着更多的事件,这可能会有所改善。

关于javascript - 当拖动子元素时使元素可拖动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38740968/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com