【发布时间】:2014-04-08 01:37:27
【问题描述】:
我目前有一个返回浏览器窗口高度和宽度的小脚本。我遇到的问题是实现一种方法,使高度和宽度从零计数到当前加载尺寸。它的功能类似于:http://jsfiddle.net/YWn9t/,但目标数字将是上述尺寸。这可以使用比 jsfiddle 更少的代码来完成吗?
HTML:
<div>
<span></span>
<span></span>
</div>
CSS:
body {text-align: center;}
div {border: 2px solid #000; display: inline-block; padding: 5px 20px; vertical-align: middle;}
span:first-of-type:after {content: "|"; margin: 0 10px;}
jQuery:
$(document).ready(function (e) {
showViewportSize();
});
$(window).resize(function (e) {
showViewportSize();
});
function showViewportSize() {
var the_width = $(window).width();
var the_height = $(window).height();
$('span:first-of-type').text(the_width);
$('span:last-of-type').text(the_height);
}
【问题讨论】:
标签: javascript jquery html css