jQuery UI: Get sortables position before/after and change.


/ Published in: JavaScript
Save to your folder(s)



Copy this code and paste it in your HTML
  1. /*
  2. <div id="rleft">
  3.   <p>etc</p>
  4.   <p>etc</p>
  5.   <p>etc</p>
  6. </div>
  7. */
  8.  
  9. $("#rleft").sortable({
  10. axis: 'y',
  11. items: "p",
  12. start: startdrag,
  13. stop: stopdrag,
  14. })
  15.  
  16. function startdrag(event, ui){
  17. var old_position = $("#rleft p").index(ui.item)
  18. ui.item.data("old", old_position)
  19. }
  20. function stopdrag(event, ui){
  21. var new_position = $("#rleft p").index(ui.item)
  22. ui.item.data("new", new_position)
  23. var old_position = ui.item.data("old")
  24. var change = new_position - old_position
  25. var moved_up = change > 0
  26. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.