javascript - offset() doesn't work in Bootstrap Modal window -


i want set drop-zone (drag drop files standard html file input) in bootstrap modal. doesn't work.

<div class="modal fade" id="mymodal" tabindex="-1" role="dialog" aria-labelledby="mymodallabel"> <div class="modal-dialog modal-lg" role="document">   <div class="modal-content">     <div class="modal-header">           <button type="button" class="close" data-dismiss="modal" aria-label="close"><span aria-hidden="true">&times;</span></button>           <h4 class="modal-title" id="mymodallabel">modal title</h4>         </div>     <div class="modal-body">        <div id="drop-zone">           <span id="filename">drop files here...</span>           <div id="clickhere"> or click here..           <input type="file" name="file" id="file" onchange="changeinput()" />        </div>     </div>     </div>     <div class="modal-footer">           <button type="button" class="btn btn-default" data-dismiss="modal">close</button>           <button type="button" class="btn btn-primary">save changes</button>     </div>   </div> </div> 

$(function () { var dropzoneid = "drop-zone"; var buttonid = "clickhere"; var mouseoverclass = "mouse-over";  var dropzone = $("#" + dropzoneid); var ooleft = dropzone.offset().left; console.log("left:"+ooleft); var ooright = dropzone.outerwidth() + ooleft; console.log("right:"+ooright); var ootop = dropzone.offset().top; console.log("top:"+ootop); var oobottom = dropzone.outerheight() + ootop; var inputfile = dropzone.find("input"); document.getelementbyid(dropzoneid).addeventlistener("dragover", function (e) {   console.log("drag");     e.preventdefault();     e.stoppropagation();     dropzone.addclass(mouseoverclass);     var x = e.pagex;     var y = e.pagey;      if (!(x < ooleft || x > ooright || y < ootop || y > oobottom)) {         inputfile.offset({ top: y - 15, left: x - 100 });     } else {         inputfile.offset({ top: -400, left: -400 });     }  }, true);  if (buttonid != "") {     var clickzone = $("#" + buttonid);      var oleft = clickzone.offset().left;     var oright = clickzone.outerwidth() + oleft;     var otop = clickzone.offset().top;     var obottom = clickzone.outerheight() + otop;      $("#" + buttonid).mousemove(function (e) {       console.log("hover");         var x = e.pagex;         var y = e.pagey;         if (!(x < oleft || x > oright || y < otop || y > obottom)) {             inputfile.offset({ top: y - 15, left: x - 160 });         } else {             inputfile.offset({ top: -400, left: -400 });         }     }); }  document.getelementbyid(dropzoneid).addeventlistener("drop", function (e) {   console.log("drop");     $("#" + dropzoneid).removeclass(mouseoverclass); }, true); }) 

example here : https://fiddle.jshell.net/2yzk77sx/

it seems element in modal returns offset() 0 , , cause problem.

is there anyways solve this?


Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -