Jquery calling function to parent element -


i have got html

<div class='aname'>     <div class='cllt'>       <img src='../img/close.png' class='cl' />       <div class='drag'>         <img src='../img/dr.png' class='dr' /></div>     </div> </div> 

and jquery function

function handle_mousedown(e){     window.my_dragging = {};     my_dragging.pagex0 = e.pagex;     my_dragging.pagey0 = e.pagey;     my_dragging.elem = this;     my_dragging.offset0 = $(this).offset();     function handle_dragging(e){         var left = my_dragging.offset0.left + (e.pagex - my_dragging.pagex0);         var top = my_dragging.offset0.top + (e.pagey - my_dragging.pagey0);         $(my_dragging.elem)             .offset({top: top, left: left});     }     function handle_mouseup(e){         $('body')             .off('mousemove', handle_dragging)             .off('mouseup', handle_mouseup);     }     $('body')         .on('mouseup', handle_mouseup)         .on('mousemove', handle_dragging); } 

source how make element draggable in jquery?; , have tried way

$('.dr').mousedown(function(){     $(this).parent().parent().parent(handle_mousedown) }); 

but not dragging it

give function second argument indicates element should dragged instead of this.

function handle_mousedown(e, elem) {    var my_dragging = {};    my_dragging.pagex0 = e.pagex;    my_dragging.pagey0 = e.pagey;    my_dragging.elem = elem;    my_dragging.offset0 = elem.offset();      function handle_dragging(e) {      var left = my_dragging.offset0.left + (e.pagex - my_dragging.pagex0);      var top = my_dragging.offset0.top + (e.pagey - my_dragging.pagey0);      my_dragging.elem        .offset({          top: top,          left: left        });    }      function handle_mouseup(e) {      $('body')        .off('mousemove', handle_dragging)        .off('mouseup', handle_mouseup);    }    $('body')      .on('mouseup', handle_mouseup)      .on('mousemove', handle_dragging);  }    $('.dr').mousedown(function(e) {    handle_mousedown(e, $(this).parent().parent().parent());  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>  <div class='aname'>      <div class='cllt'>        <img src='../img/close.png' class='cl' />        <div class='drag'>          <img src='../img/dr.png' class='dr' /></div>      </div>  </div>


Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -