3

is there a way to make Jquery ui sortable have it's item index count from bottom instead of from top?

For example:

<ul id="sortable">
    <li>Item 1</li> // ui.item.index() = 0
    <li>Item 2</li> // ui.item.index() = 1
    <li>Item 3</li> // ui.item.index() = 2
    <li>Item 4</li> // ui.item.index() = 3
</ul>

And have it like this:

<ul id="sortable">
    <li>Item 1</li> // ui.item.index() = 3
    <li>Item 2</li> // ui.item.index() = 2
    <li>Item 3</li> // ui.item.index() = 1
    <li>Item 4</li> // ui.item.index() = 0
</ul>

I'm trying to set the z-index from div.Zindex where it's z-index: (ui.item.index()*10):

$( "#sortable" ).sortable({
    stop: function(event, ui) {
        $( "#sortable li" ).map( function(){
            var updateZindex = 0;
            if($(this).index() == 0){
                updateZindex = 1000;
            }else{
                updateZindex = $(this).index()*10;
            }
            $('#parent').find('div[id='+$(this).attr('id')+']').css('z-index', updateZindex);
        });
    }
});
$( "#sortable" ).disableSelection();

Thank you

CIRCLE
  • 4,501
  • 5
  • 37
  • 56
  • details on how your trying to use it? – Prat Sep 19 '13 at 15:13
  • sorry, I've updated with the code I'm trying to fix with the `item.index()` – CIRCLE Sep 19 '13 at 15:23
  • Instead of trying to reverse the order, couldn't you just negate the sort position for the `z-index`? `1` would become `-10`, `2`->`-20`, etc. – Will M Sep 19 '13 at 15:28
  • @Will I can't do that because if I give negative z-index the div's hide behind everything including the `body` wich has a background image – CIRCLE Sep 19 '13 at 15:33
  • Hmm, pretty sure there's a way to set z-index relative to these elements only. Looking that up now... – Will M Sep 19 '13 at 15:39
  • Looks like z-index is necessarily relative http://stackoverflow.com/questions/7482840/z-index-order-for-draggable-div/7482870#7482870 You could use negative `z-index`s if you have a parent div that has a higher index than the body. Fiddle/HTML? – Will M Sep 19 '13 at 15:42
  • Why do you need this revert? Can't you use an attribute on the li markup? Can you post a jsfiddle? – Irvin Dominin Sep 19 '13 at 15:50

0 Answers0