Одинаковая высота колонок
Здравствуйте!
Подскажите пожалуйста, как решить задачку. Надо создать одинаковую высоту колонок у адаптивного дизайна. <div class="container"> <div class="content-c"></div> <div class="sidebar-prav"></div> </div> Применяю такое решение <script> jQuery(document).ready(function($) { var content = jQuery('.content-c'); var sidebarR = jQuery('.sidebar-prav'); var sidebarL = jQuery('.sidebar-lev'); var getContentHeight = content.outerHeight(); var getSidebarRHeight = sidebarR.outerHeight(); var getSidebarLHeight = sidebarL.outerHeight(); if (getSidebarRHeight != 'undefined' && getContentHeight > getSidebarRHeight) { sidebarR.css('height', getContentHeight); jQuery('.c-content').css('height', getContentHeight - 50); jQuery('#sidebar-right').css('height', getContentHeight - 50); } if (getSidebarRHeight != 'undefined' && getSidebarRHeight > getContentHeight) { content.css('height', getSidebarRHeight); //alert('2'); jQuery('.c-content').css('height', getSidebarRHeight - 50); jQuery('#sidebar-right').css('height', getSidebarRHeight - 50); } if (getSidebarLHeight != 'undefined' && getContentHeight > getSidebarLHeight) { sidebarL.css('height', getContentHeight); //alert('3'); jQuery('.c-content').css('height', getContentHeight - 50); jQuery('#sidebar-left').css('height', getContentHeight - 50); } if (getSidebarLHeight != 'undefined' && getContentHeight < getSidebarLHeight) { content.css('height', getSidebarLHeight); //alert('4'); jQuery('.c-content').css('height', getContentHeight - 50); jQuery('#sidebar-left').css('height', getContentHeight - 50); } }); </script> Но почему то все время высота центрального блока "content-c" подсчитывается неправильно. Такое ощущение, что javascript определил высоту, а после этого страница еще подзагрузилась и высота изменилась и поэтому выставляет неправльно высоту. В чем здесь проблема? Как сделать так, чтобы высота определялась именно после полной окончательной загрузке страницы? Вот пример http://myuniquebusiness.ru/3/obzor-t...-na-novyj-god/ Спасибо! |
Возможно, что в таких случаях надо использовать .offsetHeight.
<!DOCTYPE html> <html lang="ru"> <head> <meta charset="UTF-8"> <title>Пример</title> </head> <body> <div class="container"> <div class="content-c">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. </div> <div class="sidebar-prav">mollit anim id est laborum</div> </div> <script> window.addEventListener("DOMContentLoaded", function() { function $(elem){ return document.querySelector(elem) } var arr = [$('.content-c'), $('.sidebar-prav')]; var maxHeight = Math.max(arr[0].offsetHeight, arr[1].offsetHeight); arr.forEach(function(item) { item.style.height = maxHeight + 'px'; }); }); </script> <style> .container div{ width: 200px; float: left; } .content-c {background: blue} .sidebar-prav{background: orange} </style> </body> </html> |
Спасибо за помощь!!
Буду пробовать..... |
Цитата:
|
Часовой пояс GMT +3, время: 14:07. |