私はこれに沿ったものであるUIのアイデアを持っています:
- ドラッグ可能なアイテムが入った隠しコンテナがあります。
- ユーザーが何かをクリックして、コンテナーを表示します。
- ユーザーは、アイテムを収容者から「メインエリア」にドラッグできます。
- アイテムがコンテナからドラッグアウトされると、残りのアイテムを含むコンテナは非表示に戻る必要があります。
私は以下のコードに従って到達しました、しかし私は問題に遭遇しました、それは私が回避する方法を理解することができません。
アイテムの親コンテナが非表示になると、アイテムも非表示になります。さらに、スライド効果により、アイテムの配置も影響を受けます。
これをどのように解決できるかについての考えやアイデアは大歓迎です:)そして、私が間違った方向に進んでいる場合は、自由に正しい方向を指してください:)
よろしくお願いします、オラ
<style>
#container{ background-color: red; width:300px; height:200px; position:absolute; left: 200px; top:200px; display: none;}
#draggable1 {background-color: blue; width:100px; height:50px;}
#draggable2 {background-color: green; width:100px; height:50px;}
</style>
<div id="container">
<p>Original Container</p>
<div id="draggable1" class="draggable">
<p>Draggable1</p>
</div>
<div id="draggable2" class="draggable">
<p>Draggable2</p>
</div>
</div>
<div id="showContainer">Show Container</div>
<script type="text/javascript">
$(function () {
//Click to show the container
$("#showContainer").click(function () {
//Call function to toggle the visibillity of the container
toggleContainer();
});
//Set the draggable elements
$(".draggable").draggable();
//Set the container as a drop target, to be able to get the event of when
//the draggable leaves the container
$("#container").droppable();
//Bind to the event of the darggable element leaving the droppable area
$("#container").bind("dropout", function (event, ui) {
//When draggable element is dragged outside of container, hide it
toggleContainer();
});
//function to toggle the visibillity of the container
function toggleContainer() {
//Animating the toggling of visibillity with a slide effect
$("#container").toggle('slide', { direction: 'down' });
};
});