我很高兴尝试制作一个小工具来测试屏幕尺寸。到目前为止,蓝色宽度正确调整大小,但高度和文本框没有。有人注意到这段代码有什么问题吗?
页面加载时的工具正确呈现。
/* Sizing Script */
$(document).ready(function() {
var canvas = $('#canvas');
var h = $(window).height();
var w = $(window).width();
var txt = ('height: ' + h + '\n\n' + 'width: ' + w);
draw(canvas.attr('id'), canvas.height(), canvas.width(), txt);
$(window).resize(function() {
var h = $(window).height();
var w = $(window).width();
draw(canvas.attr('id'), canvas.height(), canvas.width(),txt);
});
});
function draw( id, h, w, txt) {
var paper = Raphael(id, '100%', '100%'); //create new paper instance based on holder height and width
paper.setViewBox(0, 0, 1500, 1500, true);
paper.clear();
var height_h = paper.rect(10, 0, 100, 10).attr({
fill: '#291919',
stroke: '#291919'
});
var height_l = paper.rect(10, h-10, 100, 10).attr({
fill: '#291919',
stroke: '#291919'
});
var height_v = paper.rect(55, 0, 10, h).attr({
fill: '#291919',
stroke: '#291919'
});
var width_l = paper.rect(0, 10, 10, 100).attr({
fill: '#549EFF',
stroke: '#549EFF'
});
var width_r = paper.rect(w-10, 10, 10, 100).attr({
fill: '#549EFF',
stroke: '#549EFF'
});
var width_h = paper.rect(0, 55, w-10, 10).attr({
fill: '#549EFF',
stroke: '#549EFF'
});
var textbox = paper.rect(h/2 - 50, w/2 - 100, 200, 100).attr({
fill: '#E6E6E6',
stroke: '#ddd',
'stroke-width': 5
});
var height_b = paper.rect(h / 2 - 12, w / 2 - 80, 125, 25).attr({
fill: '#291919',
stroke: '#ddd',
'stroke-width': 5,
opacity: 0.6
});
var width_b = paper.rect(h / 2 - 12, w / 2 - 45, 125, 25).attr({
fill: '#549EFF',
stroke: '#ddd',
'stroke-width': 5,
opacity: 0.6
});
var t = paper.text(h / 2 + 50, w / 2 - 50, txt).attr({
"font-size": 16,
"font-family": "Arial, Helvetica, sans-serif"
});
}
HTML
<div id="canvas"></div>
CSS
body{
width: 100%;
height: 100%;
}
#canvas{
width: 100%;
height: 100%;
text-align: center;
border: solid 1px black;
padding: 0px;
margin: 0 auto;
}
我创建了一个 jsfiddle,但它根本无法正确呈现。jsfiddle我猜如果我能解决高度问题,黑条和盒子都会正确渲染。有没有办法清除所有内容并在调整大小时强制重新渲染?