最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Animation jQuery UI draggable element back to starting position - Stack Overflow

programmeradmin1浏览0评论

I have an element, let's say a div, that I want to be able to drag and drop into another div. If the element isn't dragged into the other div I would like it to animate back to it's initial position. The draggable divs are relatively positioned. So, my question is what's the best approach? Is there a method in jQuery UI which will allow it to animate back? Or am I going to have to write it? If I do, here's my strategy:

  1. get coordinates of the draggable div on start of drag using $('#draggableElement').css('left'), and $('#draggableElement').css('top')

  2. On drag plete use the jQuery .animate to put it back in place.

Is that strategy correct? Or is there something more efficient I could be doing?

I have an element, let's say a div, that I want to be able to drag and drop into another div. If the element isn't dragged into the other div I would like it to animate back to it's initial position. The draggable divs are relatively positioned. So, my question is what's the best approach? Is there a method in jQuery UI which will allow it to animate back? Or am I going to have to write it? If I do, here's my strategy:

  1. get coordinates of the draggable div on start of drag using $('#draggableElement').css('left'), and $('#draggableElement').css('top')

  2. On drag plete use the jQuery .animate to put it back in place.

Is that strategy correct? Or is there something more efficient I could be doing?

Share Improve this question edited Aug 17, 2013 at 20:23 j08691 208k32 gold badges269 silver badges280 bronze badges asked Jul 27, 2012 at 8:39 Adam WaiteAdam Waite 18.9k23 gold badges130 silver badges149 bronze badges 3
  • 3 jqueryui./demos/droppable/#revert – Ryan Wheale Commented Jul 27, 2012 at 8:43
  • You could try using webkit for such stuff, but the ment above answers ur question! – Shouvik Commented Jul 27, 2012 at 8:43
  • Thanks Ryan, I could have sworn that wasn't there last week when I checked! – Adam Waite Commented Jul 27, 2012 at 9:19
Add a ment  | 

2 Answers 2

Reset to default 2

Have a look at this

and maybe the helper of a jquery ui draggable options -> helper.

I think this should help you. If not, please specify your question.

You need to set revert: 'invalid'

example:

$( "#draggablediv" ).draggable({helper : "clone", revert: "invalid" });

the helper:clone makes a clone when you try to drag it, when you dont drop it in the area the revert: "invalid" returns the clone to his start position.

If you want the dragable to return to his position use revert: "true"

Please see http://api.jqueryui./draggable/#option-revert

发布评论

评论列表(0)

  1. 暂无评论