我正在尝试将浏览器的宽度和高度更改为.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>
发布于 2015-04-02 11:21:25
示例
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
});
}发布于 2015-04-02 11:19:56
未登录的SyntaxError:意外令牌非法
你用‘和’。为了运行您的脚本,您需要使用‘或“。
发布于 2015-04-02 11:36:50
您所要求的最佳实践是使用响应性设计:http://responsivedesign.is/examples/playgrounds-and-sandboxes/lots-of-donuts
例如:
@media only screen and (min-width: 1300px) { #divId {width:1000px;}}
@media screen and (max-width: 860px) {#divId {width:800px;} }
@media screen and (max-width: 650px) { #divId {width:600px;}}
@media screen and (max-width: 480px) { #divId {width:400px;}}https://stackoverflow.com/questions/29411569
复制相似问题