Jquery animate top left dynamic -
i using jquery animate html5 drag , drop , wanted make same animation google drive do.
i manage :
element.bind('drag', function(e) { _.each(draggedfiles, function(id) { //draggedfiles array of id id = 'fs-row-' + id; var newrow = angular.element('body').find('div#'+ id); // element being animated newrow.animate({ width: 190, height: 50, top: e.originalevent.pagey, left: e.originalevent.pagex, }, 'medium', function() { // when animation on tag element being removed dom _.each(draggedfiles, function(id) { id = 'fs-row-' + id; angular.element('body').find('div#'+ id).remove(); }); }); }); });
the animation working fine , go mouse position. if move mouse during animation, animate not update top , left on fly instead continue move clicked instead of following mouse.
the drag event allow know position of mouse in window. possible trigger animate again until reach mouse position ?
[edit] looking @ jquery doc , found can use progress or step, can't find if possible update top , left 2 event. know?
i found answer looking jquery doc using step function, maybe in future. can edit on each step end or start of each property animated. had update end position of mouse.
var y = 0; var x = 0; element.bind('drag', function(e) { _.each(draggedfiles, function(id) { id = 'fs-row-' + id; var newrow = angular.element('body').find('div#'+ id); newrow.animate({ opacity: 1, width: 190, height: 50, top: e.originalevent.pagey, left: e.originalevent.pagex }, { duration: 400, step: function( now, tween ) { if (tween.prop === 'top') { tween.end = y; } if (tween.prop === 'left') { tween.end = x; } }, complete: function() { newrow.remove(); angular.element(dragelement).animate({ width: 190, height: 50, opacity: 1 }, 'fast'); } }); }); y = e.originalevent.pagey + 1; x = e.originalevent.pagex; });
Comments
Post a Comment