ユーザーがアップロードした画像のサイズに応じて変化する動的サイズの div を完全に中央に配置するのに問題があります。この関数は、divを他のすべてのコンテンツの上に画面の中央に絶対に配置することになっていますが、使用する画像に関係なく、わずかな割合でずれています...以下を参照してください:
http://i.imgur.com/F9NNDAH.jpg
CSSは次のとおりです。
.prompt_background {
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
background-color: black;
-moz-opacity:.50;
filter:alpha(opacity=50);
opacity:.50;
display: none;
}
.prompt_box {
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
background-color: white;
z-index: 1;
display: none;
position: fixed;
top: 50%;
left: 50%;
behavior: url(PIE.htc);
}
.prompt_content {
width: 100%;
margin: 10px;
}
そして、私がそれをロードする方法はこれです:
function showprompt() {
$('.prompt_box')
.css("margin-left", -(($('.prompt_box').width())/2)+"px") //Horizontal center
.css("margin-top", -(($('.prompt_box').height())/2)+"px"); //Vertical center
$('.prompt_background')
.css('height', $(document).height())
.css("width", $(document).width()); //Background stretch
$('.prompt_background')
.css('filter', 'alpha(opacity=50)'); //Background opacity
$('.prompt_background, .prompt_box')
.fadeIn(500); //Animation
}
HTMLに関しては、ajax経由でコンテンツをロードするのは3つの空のdivだけです
<div class="prompt_background">
</div>
<div class="prompt_box">
<div class="prompt_content">
</div>
</div>