I have a <ul>, in which I am using jQuery UI Sortable to allow the sorting of the contained <li>s.
The <li>s are styled with alternating background colours with :
.list-striped li:nth-child(odd) {
background-color: #f9f9f9;
}
I am using the Sortable start and stop functions to create a nice transition when the <li> is dragged like so:
$( ".sortable" ).sortable({
start: function(event, ui){
$(ui.item).animate({
'background-color': '#333333'
}, 'fast');
},
stop: function(event, ui){
$(ui.item).animate({
'background-color': ''
}, 'fast');
}
});
My issue now, is that when we clear the background colour, it doesn’t revert to the previous background colour (or inherit the background colour it should from the CSS). Is what I am trying to achieve possible?
Don’t use jQuery to animate colors, use
CSS transitionsinstead:CSS:
JSFiddle