Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery UI sortable, highlight selected or dragged box

Tags:

jquery

css

I am creating list of boxes to be drag around and sort. I need the selected box to be highlighted with different color than original. Following codes make other items semi transparent.

$("#sortable").sortable({ 
    axis: "y", 
    cursor: "move",
    change: function (event, ui) {}, //save the sort
    start: function (event, ui) {
        $("#sortable").css("opacity", "0.6");                                
    },
    stop: function (event, ui {
        $("#sortable").css("opacity", "1.0"); 
     }
});
like image 418
udaya shakya Avatar asked Mar 15 '26 05:03

udaya shakya


2 Answers

Your are close:

$("#sortable").sortable({
    axis: "y",
    cursor: "move",
    change: function(event, ui) {}, //save the sort
    start: function(event, ui) {
        $(ui.item).css("opacity", "0.6");
    },
    stop: function(event, ui) {
        $(ui.item).css("opacity", "1.0");
    }
});

Also I would suggest instead of directly manipulating the elements style, add and remove class to the element to modify its style (easier to maintain and globally implement).

like image 58
PseudoNinja Avatar answered Mar 16 '26 18:03

PseudoNinja


instead of using start and stop function for opacity use sortable default opacity function

$("#sortable").sortable({ 
    axis: "y", 
    cursor: "move",
    opacity: 0.5,  // set opacity to 50% while dragging
    change: function (event, ui) {} //save the sort
});
like image 26
Raheel Khan Avatar answered Mar 16 '26 19:03

Raheel Khan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!