Показать сообщение отдельно
  #6 (permalink)  
Старый 31.01.2013, 15:58
Аватар для ksa
ksa ksa вне форума
CacheVar
Отправить личное сообщение для ksa Посмотреть профиль Найти все сообщения от ksa
 
Регистрация: 19.08.2010
Сообщений: 14,123

Вот накидал макетик... Ничего не виснет.

<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<!--
<link rel="stylesheet" type="text/css" href="tmp.css" />
-->
<style type="text/css">
* {
	margin: 0;
	padding: 0;
}
#box {
	position: relative;
	border: 1px solid;
}
.box {
	position: absolute;
}
</style>
<script type="text/javascript">
var maxw=1000;
var maxh=500;
var w=100;
var h=100;
var maxi=1000;
var ab=[];
$(document).ready(function (){
	$('#box').css({
		'width': maxw+'px',
		'height': maxh+'px'
	});
	setTimeout(newDiv,0);
});
function newDiv() {
	var y,x,i;
	i=0;
	do {
		y=Math.floor(Math.random()*(maxh-h))+1;
		x=Math.floor(Math.random()*(maxw-w))+1;
		i++;
	} while ((i<maxi) && cross(y,x));
	if (i==maxi) return;
	ab[ab.length]={x: x, y: y};
	$('#box').append('<div class="box" id="b'+ab.length+'"></div>');
	$('#b'+ab.length).css({
		'top': y+'px',
		'left': x+'px',
		'width': w+'px',
		'height': h+'px',
		'background-color': color()
	});
	setTimeout(newDiv,0);
};
function cross(Y,X) {
	var i,ok;
	ok=false;
	for (i=0; i<ab.length; i++) {
		if (Math.abs(ab[i].x-X)>w) continue;
		if (Math.abs(ab[i].y-Y)>h) continue;
		ok=true;
		break;
	};
	return ok;
};
function color() {
	var s='';
	for (i=0; i<6; i++) {
		s=s+Math.floor(Math.random() * 10);
	}
	return '#'+s
};
</script>
</head>
<body>
<div id='box'></div>
</body>
</html>

Последний раз редактировалось ksa, 31.01.2013 в 16:29.
Ответить с цитированием