简体   繁体   English

Jquery ui Sortable 触发 Toggle 事件

[英]Jquery ui Sortable trigger the Toggle event

I have a simple list that I make sortable with Jquery UI.我有一个简单的列表,可以使用 Jquery UI 进行排序。

The content off one (or more) of the items is two divs, one is the title and the other is the content.一个(或多个)项目的内容是两个 div,一个是标题,另一个是内容。 The title is binded to a toggle event that hides or shows the content.标题绑定到隐藏或显示内容的切换事件。

The problem comes when I drag the item with toogle event, what happens is that the even is triggered and the contents is hide or show.当我使用togle事件拖动项目时出现问题,发生的是事件被触发并且内容被隐藏或显示。

there is a way to prevent this?有办法防止这种情况吗?

Here is sample of the problem:这是问题的示例:

 $("#list").sortable({ placeholder: "taskPlaceHolder", stop: function(e, ui) { //code here ui.item.fadeTo(250, 1); }, start: function(e, ui) { //code here ui.item.fadeTo(250, .5); } }).disableSelection(); $("#title").toggle( function() { $("#content1").hide(500); }, function() { $("#content1").show(500); });
 body { color: white }.red { background: red; }.green { background: green; }.blue { background: blue; }.taskPlaceHolder { border: 3px dashed yellow; background-color: #fff; height: 40px; padding: 8px; }
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script> <script src="https://code.jquery.com/ui/1.8.14/jquery-ui.min.js" integrity="sha256-8vGrOiH2JPV0k8i9YHEcVFr10iQ53qDbkN4ir8mJFFQ=" crossorigin="anonymous"></script> <ul id="list"> <li class="red"> <div id="title">1 - XXXXXXXX</div> <div id="content1"> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p> </div> </li> <li class="blue">2 - XXXXXXXX</li> <li class="green">3 - XXXXXXXX</li> </ul>

Drag the item in RED拖动红色项目

I figure it out, If someone have the same problem: I'm not 100% clear why, but apparently "FadeTo" somehow reset the element, and that is what triggers the other event.我想通了,如果有人有同样的问题:我不是 100% 清楚为什么,但显然“FadeTo”以某种方式重置了元素,这就是触发另一个事件的原因。

I hope this help.我希望这会有所帮助。

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

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