简体   繁体   English

我的拖放无效

[英]my drag & drop is not working

i want move my #timebase1 div into draghere div. 我想将#timebase1 div移动到draghere div。 now its move only the start of the div, i want to drop it in anywhere inside the dragehere div. 现在它的动作只是div的开始,我想将其放在dragehere div内的任何位置。

  function funct(e) { var id = e.id; mouseXY(id); } function mouseXY(id) { //alert(id); var x = event.pageX, y = event.pageY $('#' + id).css({ top: y, left: x + '' }); } 
 .activelevel1 { background-color: #EA623E; } .timescalebase { margin-top: 13px; height: 7px; position: relative; width:0px; } 
  <div id="draghere"style="width:100%;margin-top:25px;"> <div id="timebase1"draggable="true"class="timescalebase activelevel1" ondrag=funct(this)> </div> 

You must allowdrop on your target div like this : 您必须像这样在目标div上允许放置:

 function funct(e) { var id = e.id; mouseXY(id); } function allowDrop(ev) { ev.preventDefault(); } function mouseXY(id) { var x = event.pageX, y = event.pageY $('#' + id).css({ left: x }); } 
 .activelevel1 { background-color: red; width: 10px; height: 10px; } .timescalebase { margin-top: 13px; height: 7px; position: relative; } #draghere { background-color: blue; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div id="draghere" style="width:100%;margin-top:25px;" ondragover="allowDrop(event)"> <div id="timebase1" draggable="true" class="timescalebase activelevel1" ondrag="javascript:funct(this)"> </div> </div> 

EDIT 编辑

One example with jquery-ui : jquery-ui的一个示例:

https://jsfiddle.net/2gaq2r15/ https://jsfiddle.net/2gaq2r15/

$(document).ready(function(e) {
  $("#timebase1").draggable({
    containment: "#draghere",
    axis: "x"
  });
});

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

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