steam23
asked on
jquery to position elements randomly, but without overlap
I am placing a dynamic amount of elements in random positions in a parent element. Each element is 75px square and position:absolute and I'd like to make sure that their random x and y co-ordinates don't overlap those of any already positioned elements.
Points for urgency...
Points for urgency...
$('.className').each(function(){
$(this).css({ 'top':randomXToY(0,375),
'left': randomXToY(0,450),
});
});
// in case it's useful, my random function is just:
function randomXToY(minVal,maxVal,floatVal){
var randVal = minVal+(Math.random()*(maxVal-minVal));
return typeof floatVal=='undefined'?Math.round(randVal):randVal.toFixed(floatVal);
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks