I've got a list of items, each containing a checkbox. When a checkbox is ticked I'd like that item to sort itself to the beginning of the list, preferably animating as if it were being dragged with the mouse (but without a mouse cursor).
Is this possible? I've had trouble triggering draggable/sortable events in the past. I'm open to alternate solutions, it just need to be obvious where the item has moved to.
Edit: I was originally trying to ask how to make this happen on a jQuery sortable() list, but I obviously didn't communicate that very well, so I've updated the question to match all the wonderful answers.
Similar to avetarman's second example, this fiddle doesn't wait for the newly checked box to reach the top before the other ones take their rightful place. Instead, they all get animated together:
http://jsfiddle.net/ebiewener/Y5Mdt/1/
Ultimately, it's all about giving the row you're moving an absolute position so that it can slide up over the other rows, while giving the necessary CSS attributes to those other rows so that they don't immediately jump out of place when the selected row is removed from the document flow with the absolute positioning. Once that is done, the selected row loses it's absolute positioning, but is appended to the beginning of the rows. This allows all the css to essentially be "reset", so that you can proceed selecting new rows.
Check this fiddle. No plugin is used here.
http://jsfiddle.net/bN8x6/
Check this update as well. It uses relative positioning. So, during animation the placeholder is being kept.
http://jsfiddle.net/bN8x6/1/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With