页面高度自适应方法(PC、移动端都适用)

时间:2021-05-25 17:56:09

有个项目移动端的首页需要自适应。

宽度已经自适应了 , 高度也要自适应 ,先总结一下方法,PC端也适用。

$(function(){
var h = window.innerHeight;
$(".carousel-inner>.item>a>img, .carousel-inner>.item>img, .img-responsive, .thumbnail a>img, .thumbnail>img").css("height",h*0.32);
$(".database-con .col-xs-6 a").css("height",h*0.16);
$(".search-bg").css("height",h*0.12);
$(".home-footer").css("height",h*0.08);
});

把上面代码贴出来,供大家使用。