重新调整网页内容的大小
Re-sizing the webpage content
在我的项目中,我有一个网页,它有左右两个div区域。左边的div几乎占整个页面宽度的60%,右边的div大约占页面宽度的36%。当我从右侧或左侧收缩浏览器时,我想以适当的比例调整两个div区域的大小。UI是从Javascript生成的。这就是代码。
boardHolderPadding = $board.outerHeight() - $board.height();
$board.height(viewportHeight - siblingsHeight - boardHolderPadding);
this.$('#board .droptarget').setWidthAsRatioOfHeight(this.options.ratio);
$('#sidebar').width($(window).width() - $board.find('#board').width() - 50);
我尝试了JQuery调整大小插件,但没有得到我想要的正确结果。有人有什么建议吗?
感谢
参见jsfiddle示例,但我认为您只需要将宽度设置为百分比,而不是尝试计算它们-注意显示设置为内联块
<div>
<div class="small-left-column">this is the left column</div>
<div class="large-right-column">this is the right column</div>
</div>
<style>
.small-left-column {
width: 30%;
background-color: #aeaeae;
display: inline-block;
}
.large-right-column {
width: 60%;
background-color: #aeaeae;
display: inline-block;
}
</style>
所以我认为以你为例,你会有这样的
$(document).ready(function () {
$('#sidebar').addClass('small-left-column');
$('#board').addClass('large-right-column');
});
也许您正在寻找上面的纯Javascript版本:
$(document).ready(function () {
$('#sidebar').css( {
width: '30%'
backgroundColor: '#aeaeae',
display: 'inline-block'
});
$('#board').css({
width: '60%',
backgroundColor: '#aeaeae',
display: 'inline-block'
});
});
我在Javascript中以不同的方式完成了这项工作,我希望这将有助于人们在遇到类似的问题时进行修复
relativeSize : function(width, height){
var boardWidth = this.$("#board").width(),
boardHeight = this.$("#board").height(),
newcard = this.$("#newCard").width(),
space = width - boardWidth - newcard;
ratio = space / width * 3; //used to increment the ratio with 3 as the ratio is very tiny value, this will help to increase minimizing size
bheight = boardHeight - 25; // used to reduce the height by 25px, u can use any amount to match ur ratio
var relHeight = (space < ratio) ? bheight : height;
return relHeight;
}
感谢
相关文章:
- Firefox:根据实际内容调整iframe的大小
- 如何在没有文本区域或文本字段的浏览器中编辑网页内容
- 通过javascript在同一个打开的选项卡中重新加载新的网页内容
- 如何使用Perl访问JavaScript驱动的网页内容
- 用Instagram提要填充网页并调整大小
- 重新调整网页内容的大小
- 无需ajax即可实时更改网页内容
- 在同一网页上调整多个svg图的大小
- 花式框内容调整为 HTML
- 将网页内容调整在固定大小的 iframe 上
- 是否可以根据输入的内容调整文本区域的大小
- 需要了解跟踪代码在网页内容中的工作方式
- 在 Java 中读取动态网页内容
- 用于重复获取网页内容的程序
- 如何格式化从javascript加载的网页内容
- 如何根据ExtJS的内容调整窗口宽度
- 根据内部内容调整所有文本区域的大小
- iFrame根据框架内的动态内容调整大小
- 用AJAX响应中的内容替换网页内容
- 如何在移动设备上调整网页内容宽度,以始终适合任何缩放级别的屏幕