Advertisement
Guest User

Untitled

a guest
Jul 25th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. <body>
  2.  
  3. <div id="sortable">
  4. <?php foreach($data as $row){ ?>
  5. <div class="alert alert-success" data-id="<?php echo $row['id'] ?>" role="alert"><?php echo $row['div-name']; ?></div>
  6. <?php } ?>
  7. </div>
  8.  
  9. </body>
  10.  
  11.  
  12. Sctript part:
  13.  
  14. <script>
  15. $( function() {
  16. var lastMoved = null;
  17. $("#sortable div").mousedown(function(){
  18. lastMoved = this;
  19. });
  20. $("#sortable").sortable({
  21. start: function(e, ui) {
  22. //alert("");
  23. // console.log("Prev: "+$(this).attr('data-id'));
  24. },
  25. update: function(event, ui) {
  26. alert("Moving: "+$(lastMoved).attr("data-id"));
  27. alert("Moved to: "+parseInt($(lastMoved).index()+1));
  28. },
  29. stop: function(event, ui) {
  30. var data = "";
  31.  
  32. $("#sortable div").each(function(i, el){
  33. var p = $(el).attr("data-id").toLowerCase().replace(" ", "_");
  34. data += p+"="+parseInt($(el).index()+1)+",";
  35. });
  36. console.log(data.slice(0, -1));
  37.  
  38. }
  39. });
  40. } );
  41. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement