Показать сообщение отдельно
  #6 (permalink)  
Старый 30.01.2019, 18:36
Профессор
Отправить личное сообщение для Dilettante_Pro Посмотреть профиль Найти все сообщения от Dilettante_Pro
 
Регистрация: 27.11.2015
Сообщений: 2,899

Результат должен таким получиться?
<style>
.cell {
    position:absolute;
    width: 150px;
}
</style>
<div class="cont">
</div>
<script>
var container = document.querySelector(".cont");
var color = ["red","blue","green"],
tp = [], height = [];
for(var i=0;i<3;i++){
   tp[i] = []; height[i] = [];
   for(var j=0;j<4;j++){
       var cell = document.createElement('div');
       cell.style.backgroundColor = color[i];
       cell.style.left = (10 + j * 160 ) + "px";
       height[i][j] = Math.random() * 130 + 20;
       cell.style.height = height[i][j] + "px";
       tp[i][j] = i == 0? 10:(tp[i - 1][j] + height[i - 1][j] + 10) ;   
       cell.style.top = tp[i][j] + "px";
       cell.classList.add("cell");
       container.appendChild(cell);
   }
}
</script>

Последний раз редактировалось Dilettante_Pro, 30.01.2019 в 18:39.
Ответить с цитированием