Jquery's可调整大小的Div'调整大小时,s“宽度”和“高度”将变为0
Jquery's Resizable Div's Width and Height turns to 0 when resize
我有这个代码:
<table>
<tr>
<td id="parent">
<div id="child"></div>
</td>
</tr>
</table>
我的JavaScript代码:
$('#child' ).resizable({
animate: true,
helper: '.ui-resizable-helper',
maxWidth: 500,
maxHeight: 500,
aspectRatio: true
});
使用上面的代码,我的可调整大小的div
可以按预期工作,但当我添加containment
选项时,无论向哪个方向调整大小,div
的width
和height
都会调整为0
。
$('#child' ).resizable({
animate: true,
helper: '.ui-resizable-helper',
maxWidth: 500,
maxHeight: 500,
aspectRatio: true,
containment: '#parent'
});
为什么会这样?是虫子吗?
尝试添加此CSS:
#parent {
width: 500px;
height: 500px;
}
问题不在于#父项,而在于#子项。应用以下CSS,使其具有基本起始大小。
#child {
height:200px;
width:200px;
}
你也可以在这里看到我的小提琴,用你的代码来说明变化。
<table>
<tr>
<td>
<div class="child" style="border:solid 1px red;">
</div>
</td>
<td>
<div class="child" style="border:solid 1px red;">
<p>this is a test
</p>
</div>
</td>
</tr>
</table>
为子定义最小宽度和高度
.child {
min-width:50px;
min-height:50px;
}
将containment
设置为document
,并添加默认的minHeight
、minWidth
值。
var defaultHeight = $('#child').height();
var defaultWidth = $('#child').width();
$('.child').resizable({
animate: true,
helper: '.ui-resizable-helper',
minHeight:defaultHeight,
minWidth:defaultWidth,
maxWidth: 500,
maxHeight: 500,
aspectRatio: true,
containment: 'document'
});
小提琴
相关文章:
- 设置正文高度宽度 CSS 表达式
- 更新画布上的高度/宽度并重新开始绘制
- 使用 Jquery 加载页面时的高度宽度问题
- 修改网格高度/宽度
- 通过在运行时使用 CSS 设置其高度/宽度来拉伸 img 会产生奇怪的渐变
- 模态框高度宽度根据 iframe 的高度宽度进行固定
- 在使用Javascript / Asp.net 上传之前获取文件高度宽度
- 如何使图像无论屏幕高度/宽度如何都停留在屏幕底部
- 使用CSS旋转元素后使用高度/宽度100%
- 将元素高度/宽度设置为百分比值和像素值的组合
- JQuery - 同时设置css和实际宽度/高度宽度一个函数
- ExtJS门户布局问题(内部元素的自动高度/宽度)
- CSS/Javascript解决方案,可根据图像方向自动应用高度/宽度属性
- JavaScript/JQuery函数来获取HTML元素的原始高度/宽度
- 拉伸高度/宽度以适应屏幕