javascript - Building drag and drop navigation tabs -


i'm working on building new website purely learning purposes , want try , implement drag/drop sorting system. aware jquery provide sortable ui component http://jqueryui.com/sortable/ want have go @ designing , building system scratch (seen learning purposes).

when comes javascript have admit novice, wondering if of offer 2 cents against current thinking of how program work:

  • an un-ordered list sits @ top of page (navigation bar), each item assigned class 'draggable x' x current position in list
  • an event listener bound each li element within list
  • when on-mouse-down made on element variable set telling cell has been clicked, creates thumbnail under cursor (hides old cell) , allows user drag
  • when mouse released list item slotted new position updating class number, whilst decrementing class numbers behind it

questions:

1) main problem is, how detect when have passed li element when dragging? assume width n has been passed, each cell of variable length making solution inappropriate.

2) assuming going need use ajax handle callback, otherwise going undesired page refreshes (right)?

hopefully won't receive down votes - want stress not seeking solution guys, have used these forums long enough know don't demand code community without providing of own work! i'd feedback on initial draft answers 2 questions asked above.

thanks in advance time

alex.

if using jquery can avoid having know order items in.

the .index() function return position of item relative siblings.

you can keep track of element want move adding working class on mouse down even. (i use .draging in example)

on mouseup event find our old item class added. depending on element first compared other, insert working element before or after element mousedup on , remove working class.

here example http://jsfiddle.net/v72le/2/

function swap(dragable, draging) {     //find direction of move move item based on direction     var = $(dragable).index();     var = $(draging).index();      if (from > -1 && > -1) {         var direction = - to;         if (direction > 0) {             $(draging).insertafter($(dragable));         } else if (direction < 0) {             $(draging).insertbefore($(dragable));         }     } } 

Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -