javascript - Moving the order of screen items with a mouse click -
on screen have simple list of items:
- item 1
- item 2
- item 3
i have seen examples of user can click on item , change position in list mouse.
mu question is, how done? javascript function of sorts?
you can use jquery ui library accomplish easily. follow snippet
#sortable { list-style-type: none; margin: 0; padding: 0; width: 60%; } #sortable li { background:#aeaeae; margin: 0 3px 3px 3px; padding: 0.4em; padding-left: 1.5em; font-size: 1.4em; height: 18px; } #sortable li span { position: absolute; margin-left: -1.3em; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script> <script> $(function() { $( "#sortable" ).sortable(); $( "#sortable" ).disableselection(); }); </script> <ul id="sortable"> <li>item 1</li> <li>item 2</li> <li>item 3</li> <li>item 4</li> <li>item 5</li> <li>item 6</li> </ul>
Comments
Post a Comment