Javascript 动态高度/最大高度和溢出
我正在为我的应用程序创建一个任务管理器,我正在尝试计算小部件的高度,然后在它满足要求时做一些事情。基本上,我希望得到窗口的高度减去另一个数字,以获得任务小部件的最大高度(最小高度已经设置)。然后我想动态地获得div的实际高度,如果它等于max height,那么我想更改一些css属性。我使用jQuery1.5.2来实现这一点。这是我所拥有的Javascript 动态高度/最大高度和溢出,javascript,jquery,css,Javascript,Jquery,Css,我正在为我的应用程序创建一个任务管理器,我正在尝试计算小部件的高度,然后在它满足要求时做一些事情。基本上,我希望得到窗口的高度减去另一个数字,以获得任务小部件的最大高度(最小高度已经设置)。然后我想动态地获得div的实际高度,如果它等于max height,那么我想更改一些css属性。我使用jQuery1.5.2来实现这一点。这是我所拥有的 $(document).ready(function() { //Get the height for #tasks var tH = Math.round
$(document).ready(function() {
//Get the height for #tasks
var tH = Math.round($(window).height() - 463);
$('#tasks').css('height', tH); //Make it the max height
var ti = Math.round($("#tasks").height()); //Get actual height of #tasks
if(tH==ti){ // If #tasks actual height is equal to the max-height than do...
//alert('true');
$('.taskItems').css('width', '172px');
$('.tT, .tD').css('width', '135px');
console.debug(ti + ' ' + tH);
}else{
alert(tH + ' ' + ti);
console.debug(ti + ' ' + tH);
}
});
只要“警报('true')”首先触发,并且“最大高度”更改为“高度”,这项功能就非常有效
注释掉警报后,if语句将停止工作
当
$(“#tasks”).css('height',tH)更改为$(“#tasks”).css('max-height',tH)
价值观是疯狂的偏离。示例:78/130。css如下所示
#tasks {
border:1px solid #D1D1D1;
border-top:none;
color:rgb(82,124,149);
display:inline-block;
font-size:12px;
margin:0px 0px 0px 1px;
overflow:auto;
width:194px;
}
任何帮助都将不胜感激。提前感谢。每次调整窗口大小时,我都会使用以下命令:
jQuery(document).ready(function () {
jQuery(window).resize(function () {
//alert("window changed");
resizeDivs();
});
});
function resizeDivs() {
var clientWidth = jQuery(window).width();
var clientHeight = jQuery(window).height();
var newHeight = 100;
var newWidth = 100;
var firstDatasegment = jQuery(".datasegment")[0];
if (!jQuery(firstDatasegment).width()) {
currentWidth = jQuery(firstDatasegment).clientWidth;
newHeight = currentWidth - (currentWidth / 7);
newWidth = currentWidth;
}
else {
//currentWidth = jQuery(".datasegment")[0].css("width");
currentWidth = jQuery(firstDatasegment).width();
newHeight = currentWidth - (currentWidth / 7);
newWidth = currentWidth;
}
jQuery(".datasegment").height(newHeight);
jQuery(".sidemenu").height(clientHeight);
jQuery(".maindatacontent").height(clientHeight);
jQuery(".text-glow").css("font-size", (clientWidth / 50) + "px");
jQuery(".hovermenuicon .menudesc").not('.bucketText').css("font-size", (clientWidth / 50) + "px");
jQuery("td.menudesc span:first-child").not('.bucketText').css("font-size", (clientWidth / 50) + "px");
jQuery(".sidemenudesc").css("font-size", (clientWidth / 80) + "px");
jQuery(".datavalue").css("font-size", (clientWidth / 80) + "px");
jQuery(".mainmenuitem").css("font-size", (clientWidth / 50) + "px");
jQuery(".qireportgridview table").css("font-size", (clientWidth / 80) + "px");
jQuery(".scrolldivbig").height(clientHeight);
}
为了让我能给你更多的帮助,我需要看看你的最基本的html,然后我会用一个工作示例相应地修改代码
嗯
$('').height()
作为setter!--><代码>$(“#任务”)。高度(th)代码>删除警报时,您的else分支没有执行任何操作。您是否获得了一些有关该div在页面中的外观的html?