我正在尝试将浏览器的宽度和高度更改为.test
div。每当我调整浏览器大小时,当前值都应更改。
$(document).ready(
function() {
window.onresize = function(event) {
resizeDiv();
}
function resizeDiv() {
var vpw=window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
var vph=window.innerHeight || document.documentElement.clientHeight ||document.body.clientHeight;
$(‘.test’).css({‘height': vph + ‘px’});
}
);
.test
{
background: green;
padding: 20px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="test"></div>
例子
js
function resize() {
$(".test").css({
width: $(window).width(),
height: $(window).height()
});
}
resize();
$(window).resize(function(){
resize();
});
如果要减去一些像素
function resize() {
$(".test").css({
width: $(window).width() - 15,
height: $(window).height() - 15
});
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句