动态高度/最大高度和溢流
Dynamic height/max-height and overflow
我正在为我的应用程序创建一个任务管理器,我正在尝试计算小部件的高度,然后在它满足要求时采取措施。基本上,我想得到窗口的高度减去另一个数字,以获得任务小部件的最大高度(已经设置了最小高度)。然后我想动态地获得div的实际高度,如果它等于最大高度,我想更改一些css属性。我使用的是jquery 1.5.2。这是我的。。。
$(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);
}
});
只要"alert('true')"首先启动,并且将"max height"height",此操作就非常有效。
当警报被注释掉时,if语句将停止工作。
当
$("#任务").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才能工作,然后我会用一个工作示例相应地更改代码。
hth
-
您也可以使用
$('').height()
作为setter!-->$('#tasks').height(th);
-
当使用$('').css('height':myVal)时,请记住,您需要指定一个单位(例如px)。你现在不这么做。
-
是什么意思
当警报被注释掉时,if语句将停止工作。
当你解除警报时,你的其他分支没有做任何事情。
相关文章:
- 使用JavaScript根据窗口/视口的高度动态调整图像大小
- javascript skrollr基于动态内容更新窗口高度
- window.open根据动态内容自动调整高度和宽度
- JQuery mCustomScrollbar动态高度
- 动态潜水高度jQuery.Load()不工作
- 使用setIntervel()以动态高度偏移具有固定页眉的页面上的内容
- 如何根据主体高度动态更改元素边距顶部
- 动态高度/最大高度和溢流
- 根据页眉和页脚高度更改高度的动态内容
- 如何在浏览器宽度/高度变化时动态调整图像网格的大小
- 动态增加 iframe 高度
- 在javascript中动态修改掩码高度
- fullPage.js在使用scrollOverflow时未检测到动态生成内容的高度
- 如何在svg高度动态变化时使用viewbox
- 根据屏幕高度动态填充框
- 如何根据元素高度动态调整iframe高度
- Div是根据窗口高度动态调整大小的,但在HTML中添加更多内容时失败
- 根据高度动态添加内容
- 如何增加谷歌多边形对话框的高度动态
- Iframe的高度[动态]每2秒