div中图片水平垂直居中
程序员文章站
2022-04-24 16:49:29
...
<div id="Container" data-options="region:'center',maximized:true" >
<span><img id="image" alt="image"/></span>
</div>
对应样式表:
#Container
{
display:table;
text-align:center;
}
#Container span
{
display:table-cell;
vertical-align:middle;
}
js中动态加载图片:
function loadimg() {
// var img = document.getElementById("image");
// img.src = "1.jpg";
//防止网页图片刷新闪烁 更改如下:
var bufferImage = new Image();
bufferImage.src = "1.jpg";
var img = document.getElementById("image");
img.src = bufferImage.src;
}