基于jquery实现的图片在各种分辨率下未知的容器内上下左右居中

2022-10-22,,,,

div:

. 代码如下:

<p class="pic_conent">
<p class=" fn-pr pic_layer">
<!--图片文字介绍透明层-->
<section class="bg text_layer_home p10 font-yahei fn-bc">
   <h2 class="f14 fefefe">${pic.desc}</h2>
<aside class="f12 bbb">
<c:if test="${not empty pic.poi}">
<span class="scenery fn-fl">${pic.poi}</span>
</c:if>
<span class="fn-fr mt10">by ${pic.username}</span>
</aside>
</section>
<img src="${pic.picurl}" width="320" height="420" />
</p>
</p>

 

css:

 

. 代码如下:

.pic_conent{
height: 720px;/*这个高度会被js改掉*/
text-align: center;
display: table-cell;
vertical-align: middle;
}
.pic_layer{text-align:center; width:100%; display:inline-block; vertical-align:middle;}

jquery:

. 代码如下:

$(function() {
var surh = $(window).height();
$(".pic_conent").height(surh);
window.onresize=function(){
var surh = $(window).height();
$(".pic_conent").height(surh);
}

《基于jquery实现的图片在各种分辨率下未知的容器内上下左右居中.doc》

下载本文的Word格式文档,以方便收藏与打印。