1. 程式人生 > >div中圖片水平垂直居中

div中圖片水平垂直居中

<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;
 }