我有这个函数可以随着浏览器窗口大小的变化动态计算视口的宽度和高度。现在我想在屏幕上显示该值,但它不起作用。有任何想法吗?
JS:
<script type="text/javascript">
var viewportWidth = $(window).width();
var viewportHeight = $(window).height();
$('viewport').html(viewportWidth);
$('viewport').html(viewportHeight);
$(window).resize(function() {
$('viewport').html(viewportWidth);
$('viewport').html(viewportHeight);
});
</script>
HTML:
<div id="viewport">width and height should be displayed here dynamically</div>
谢谢