一旦掉落的物品数量达到一定限度,请避免掉落

时间:2015-06-28 23:31:05

标签: jquery jquery-ui-draggable

我正在使用Jquery UI Draggable。 我试图避免一旦接收到该项目的div达到限制就丢弃物品。如下所示,这是我的代码。

import random

x = input("Enter a number: ")
for i in range(len(x)):
   randomGuess = random.randrange(1,10)
   while randomGuess != int(x[i]):
      print('Digit',i,'not found')
      randomGuess = random.randrange(1,10)
   print('Digit',i,'found:',x[i])

JS小提琴示例:http://jsfiddle.net/r1Lnxby9/

1 个答案:

答案 0 :(得分:1)

修改,更新

尝试从ondragstart="drag(event)"移除draggable="true"htmldrag js未显示tolerance:"touch".droppable()选项设置$("> li", this).length;将count替换为$("#grid-list").each()>=; >的{​​{1}} 1如果预期结果是.droppable()元素中event.preventDefault()元素的最大值;在event.stopPropagation()事件

中致电over $("#list-albuns, #grid-list").sortable({ connectWith: ".connectedSortable" }).disableSelection(); $("#grid-list").droppable({ tolerance: "touch", over: function(event, ui) { if ($("> li", this).length >= $(this).data("albumlist")) { event.preventDefault(); event.stopPropagation(); alert("limit"); } } });



ul li {
  display: inline-block;
  list-style: none;
}

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js">
</script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js">
</script>

<ul id="list-albuns" class="connectedSortable ui-sortable">
  <li id="0" class="ui-sortable-handle">
    <input type="hidden" name="albumId[]" value="0">
    <img id="dragimg0" height="126" width="126" src="http://userserve-ak.last.fm/serve/126/51552793.png" alt="Appetite for Destruction">
  </li>
  <li id="2" class="ui-sortable-handle">
    <input type="hidden" name="albumId[]" value="2">
    <img id="dragimg2" height="126" width="126" src="http://userserve-ak.last.fm/serve/126/97176319.png" alt="Use Your Illusion II">
  </li>
  <li id="3" class="ui-sortable-handle">
    <input type="hidden" name="albumId[]" value="3">
    <img id="dragimg3" height="126" width="126" src="http://userserve-ak.last.fm/serve/126/89710469.png" alt="40 Seasons - The Best Of Skid Row">
  </li>
  <li id="5" class="ui-sortable-handle">
    <input type="hidden" name="albumId[]" value="5">
    <img id="dragimg5" height="126" width="126" src="http://userserve-ak.last.fm/serve/126/56005467.jpg" alt="Danger Danger">
  </li>
  <li id="6" class="ui-sortable-handle">
    <input type="hidden" name="albumId[]" value="6">
    <img id="dragimg6" height="126" width="126" src="http://userserve-ak.last.fm/serve/126/85595741.jpg" alt="Screw It [Italy Bonus Tracks]">
  </li>
  <li id="7" class="ui-sortable-handle">
    <input type="hidden" name="albumId[]" value="7">
    <img id="dragimg7" height="126" width="126" src="http://userserve-ak.last.fm/serve/126/90791541.jpg" alt="Detonator">
  </li>
</ul>Drop Here:
<ul id="grid-list" data-albumlist="1" class="connectedSortable" style="width:500px; height:200px;display:block; border:2px solid black;"></ul>
&#13;
    const string serviceUri = "http://localhost:54123/MyService";
    var host = HostFactory.New(configurator =>
    {
        configurator.Service<WcfServiceWrapper<MyServiceClass, IMyServiceClass>>(serviceConfigurator =>
        {
            serviceConfigurator.ConstructUsing(x =>
                new WcfServiceWrapper<MyServiceClass, IMyServiceClass>("MyService", serviceUri));
            serviceConfigurator.WhenStarted(service => service.Start());
            serviceConfigurator.WhenStopped(service => service.Stop());
        });
        configurator.RunAsLocalSystem();

        configurator.SetDescription("Runs My Service.");
        configurator.SetDisplayName("MyService");
        configurator.SetServiceName("MyService");
    });
&#13;
&#13;
&#13;

jsfiddle http://jsfiddle.net/r1Lnxby9/2/