Javascript-форум (https://javascript.ru/forum/)
-   Internet Explorer (https://javascript.ru/forum/css-html-internet-explorer/)
-   -   В IE не меняется высота дива (https://javascript.ru/forum/css-html-internet-explorer/15137-v-ie-ne-menyaetsya-vysota-diva.html)

gh321 14.02.2011 21:51

В IE не меняется высота дива
 
Есть небольшой скрипт который меняет(уравнивает) высоты дива в зависимости от количества текста, не работает в IE8 (в режиме совместимости и в IE7).
Алерт выводит новое/полученную высоту но визуально высота дива не меняется (остается та которая задана в CSS)
window.onload = function(){

        var sidebar = document.getElementById("sidebar").offsetHeight;

        var txt = document.getElementById("text_div").offsetHeight;

        if(sidebar<965&&txt<965)return;

        if(sidebar>txt){

         document.getElementById('text_div').style.height = (sidebar-20)+'px';

         alert('text_div = '+document.getElementById('text_div').style.height);
          }
            else if(sidebar<txt){

            document.getElementById('sidebar').style.height = (txt-20)+'px';

            alert('sidebar = '+document.getElementById('sidebar').style.height);
         }
}


Возможно дело в CSS
Код:

#sidebar {
          min-height: 964px;
          height: auto;
          float:left;
          width:231px;
          ...
  }
#sidebar p { font-size:14px;
            padding:0 10px;}

#text_div {         
         
          min-height: 964px;
          height: auto;

          margin:0px 0px 0 251px;
          width:auto;
          vertical-align:top;

          padding:10px 20px 10px 20px;
          }

В FF и Opera скрипт работает.

ksa 15.02.2011 09:19

gh321, ты можешь сделать полный тестовый пример? Не куски...

Вёрстка у тебя не в почёте? Зачем сразу скрипты подключать?

Иваннн 15.02.2011 12:33

ksa,
а как он поравняет высоту блоков (эмуляция фоном не в счет)?
gh321, можно гадать, но лучше, покажи HTML код.

ksa 15.02.2011 14:22

Цитата:

Сообщение от Иваннн
а как он поравняет высоту блоков

Тестовый пример где? Я же не вижу с чем ты там работаешь...

Цитата:

Сообщение от Иваннн
эмуляция фоном не в счет

Чем она плоха? :)

Если вовсе ну никак... Таблица выручит. ;) Ну не скрипты же писать в каждый след...

gh321 15.02.2011 22:25

Цитата:

Сообщение от ksa
gh321, ты можешь сделать полный тестовый пример? Не куски...

Причину нашел - в файле для htc для округления углов в IE.


.ieroundbox{
border-radius: 15px;              /*для всех браузеров с поддержкой css3*/
behavior:url(./skins/css/border-radius.htc); /* подключаем наш htc скрипт который и будет округлять углы в ie*/
}

Если этот сss блок за комментировать в IE скрипт работает
<div id="sidebar" class="ieroundbox">
    </div>

    <div id="text_div" class="ieroundbox">              
    </div>


Сам файл из интернета

border-radius.htc
Changes by Nick Fetchak:
- IE8 standards mode compatibility
- VML elements now positioned behind original box rather than inside of it - should be less prone to breakage
Published date : 2009/11/18*/


<public:attach event="oncontentready" onevent="oncontentready('v08vnSVo78t4JfjH')" />
<script type="text/javascript">

// findPos() borrowed from [url]http://www.quirksmode.org/js/findpos.html[/url]
function findPos(obj) {
	var curleft = curtop = 0;

	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
	}

	return({
		'x': curleft,
		'y': curtop
	});
}

function oncontentready(classID) {
  if (this.className.match(classID)) { return(false); }

	if (!document.namespaces.v) { document.namespaces.add("v", "urn:schemas-microsoft-com:vml"); }

	this.className = this.className.concat(' ', classID);
	var arcSize = Math.min(parseInt(this.currentStyle['-moz-border-radius'] ||
	                                this.currentStyle['-webkit-border-radius'] ||
	                                this.currentStyle['border-radius'] ||
	                                this.currentStyle['-khtml-border-radius']) /
	                       Math.min(this.offsetWidth, this.offsetHeight), 1);
	var fillColor = this.currentStyle.backgroundColor;
	var fillSrc = this.currentStyle.backgroundImage.replace(/^url\("(.+)"\)$/, '$1');
	var strokeColor = this.currentStyle.borderColor;
	var strokeWeight = parseInt(this.currentStyle.borderWidth);
	var stroked = 'true';
	if (isNaN(strokeWeight)) {
		strokeWeight = 0;
		strokeColor = fillColor;
		stroked = 'false';
	}

	this.style.background = 'transparent';
	this.style.borderColor = 'transparent';

	// Find which element provides position:relative for the target element (default to BODY)
	var el = this;
	var limit = 100, i = 0;
	while ((typeof(el) != 'unknown') && (el.currentStyle.position != 'relative') && (el.tagName != 'BODY')) {
		el = el.parentElement;
		i++;
		if (i >= limit) { return(false); }
	}
	var el_zindex = parseInt(el.currentStyle.zIndex);
	if (isNaN(el_zindex)) { el_zindex = 0; }
	//alert('got tag '+ el.tagName +' with pos '+ el.currentStyle.position);

	var rect_size = {
		'width': this.offsetWidth - strokeWeight,
		'height': this.offsetHeight - strokeWeight
	};
	var el_pos = findPos(el);
	var this_pos = findPos(this);
	this_pos.y = this_pos.y + (0.5 * strokeWeight) - el_pos.y;
	this_pos.x = this_pos.x + (0.5 * strokeWeight) - el_pos.x;

	var rect = document.createElement('v:roundrect');
	rect.arcsize = arcSize +'px';
	rect.strokecolor = strokeColor;
	rect.strokeWeight = strokeWeight +'px';
	rect.stroked = stroked;
	rect.style.display = 'block';
	rect.style.position = 'absolute';
	rect.style.top = this_pos.y +'px';
	rect.style.left = this_pos.x +'px';
	rect.style.width = rect_size.width +'px';
	rect.style.height = rect_size.height +'px';
	rect.style.antialias = true;
	rect.style.zIndex = el_zindex - 1;

	var fill = document.createElement('v:fill');
	fill.color = fillColor;
	fill.src = fillSrc;
	fill.type = 'tile';

	rect.appendChild(fill);
	el.appendChild(rect);

	var css = el.document.createStyleSheet();
	css.addRule("v\\:roundrect", "behavior: url(#default#VML)");
	css.addRule("v\\:fill", "behavior: url(#default#VML)");

	isIE6 = /msie|MSIE 6/.test(navigator.userAgent);
	// IE6 doesn't support transparent borders, use padding to offset original element
	if (isIE6 && (strokeWeight > 0)) {
		this.style.borderStyle = 'none';
		this.style.paddingTop = parseInt(this.currentStyle.paddingTop || 0) + strokeWeight;
		this.style.paddingBottom = parseInt(this.currentStyle.paddingBottom || 0) + strokeWeight;
	}

	if (typeof(window.rounded_elements) == 'undefined') {
		window.rounded_elements = new Array();

		if (typeof(window.onresize) == 'function') { window.previous_onresize = window.onresize; }
		window.onresize = window_resize;
	}
	this.element.vml = rect;
	window.rounded_elements.push(this.element);
}

function window_resize() {
	if (typeof(window.rounded_elements) == 'undefined') { return(false); }

	for (var i in window.rounded_elements) {
		var el = window.rounded_elements[i];

		var strokeWeight = parseInt(el.currentStyle.borderWidth);
		if (isNaN(strokeWeight)) { strokeWeight = 0; }

		var parent_pos = findPos(el.vml.parentNode);
		var pos = findPos(el);
		pos.y = pos.y + (0.5 * strokeWeight) - parent_pos.y;
		pos.x = pos.x + (0.5 * strokeWeight) - parent_pos.x;

		el.vml.style.top = pos.y +'px';
		el.vml.style.left = pos.x +'px';
	}

	if (typeof(window.previous_onresize) == 'function') { window.previous_onresize(); }
}

</script>

Можно ли сохранить использования этого файла,и при этом уравнивать дивы скриптом.
В чем причина - этот скрипт меняет элементы так что второй скрипт
не работает (хоть новая высоты передается диву - алертом выводится
по крайней мере)??

ksa 16.02.2011 10:48

Цитата:

Сообщение от gh321
Сам файл из интернета

Вообще-то я спрашивал про простенький тестовый пример... :D

gh321 16.02.2011 21:30

ksa
Что Вы все таки можете сказать о том, что действие файла (скрипта border-radius.htc) на элементы( здесь дивы) - приводит тому что не работает скрипт
document.getElementById('text_div').style.height = (sidebar-20)+'px';

то есть эта строка.

ksa 16.02.2011 21:35

Цитата:

Сообщение от gh321
Что Вы все таки можете сказать

Я пока ничего не говорю... :)
Я жду простенький тестовый пример, он-то и прольёт свет на твою проблему.


Часовой пояс GMT +3, время: 07:17.