javascript - How to implement drag and drop image? -
how implement function users can upload images , drag , drop them in order present photos? i'm using ror framework. gems perhaps?
one way put images in list , give each li data-attribute it's image id, like:
<ul> <li data-image_id="1"><img src="/image1.png" /></li> <li data-image_id="2"><img src="/image2.png" /></li> </ul>
then write nice javascript code (you use jquery plugins http://farhadi.ir/projects/html5sortable/) , use callbacks end of dragging. in callback write little code loops list, parses data-image_id values , sends data server further processing (by storing 'position' int in database example).
ps. advice use position field desc new images, 0/null position, automatically end last 1 in row. client thrilled not having re-arrange images after added 4 new images ordered set.
Comments
Post a Comment