tags:

views:

15

answers:

1

i have a bunch of divs that are representing cards in a hand. depending on how many are drawn, i want to be able to have them start to stack on top of each other so that the hand container div is only one row deep. the card divs are also set up as draggables so this is kind of me trying to figure out a way to auto sort them. would using jquerys position setters be the best way to go about this?

A: 

i ended up taking the width of the container div and manually spacing each element in it.

    function alignHand(){
            var cards = $(".inHand");
            var totalWidth = 0;
            var width = $('#hand').width() - 140;
            cards.each(function(e){
                    totalWidth = totalWidth + 1;
                    $(this).addClass('cardInHand' + totalWidth);
                    $(this).css('position','absolute');
                    $(this).css('left',width/cards.length * (totalWidth - 1) + 'px');

            });
griff.steni.us
this seems like a good solution since i am going to use ajax to draw cards, i can just call this script to do the cards in hand when old ones are played or new ones are drawn.
griff.steni.us