基于jquery实现的图片在各种分辨率下未知的容器内上下左右居中
DIV:
代码如下:
<div class="pic_conent"> <div 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" /> </div> </div>
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); }
相关推荐
cas的无名 2020-02-18
chouliqingke 2020-02-13
云端轻躺 2007-09-04
GonaShrimp 2019-09-02
lionelf 2012-04-07
XTUxiaoxin 2011-09-01
shouen 2011-01-26
流萤 2019-06-26
dalong 2013-07-22
阳光之吻 2019-06-21
zgxzowen 2008-08-21
gcong 2019-06-13
liubang000 2015-08-17
sunshunli 2011-03-11
yangxinhua 2018-12-31
学无涯愈进而愈惘 2018-08-30
yinghuihong 2018-02-25