您好,请看一下我的网站,有问题的代码片段我必须将我的图像居中,因为我从来没有用过 css-html 方法。有时它会居中加载,有时不会,请告诉我如何使我的图像在页面加载时居中。
<script type="text/javascript"> //Centering Script
$(document).ready(function () {
updateContainer();
$(window).resize(function() {
updateContainer();
});
});
function updateContainer() {
(function ($) {
$.fn.vAlign = function() {
return this.each(function(i){
var h = $(this).height();
var oh = $(this).outerHeight();
var mt = (h + (oh - h)) / 2;
$(this).css("margin-top", "-" + mt + "px");
$(this).css("top", "50%");
$(this).css("position", "absolute");
});
};
})(jQuery);
(function ($) {
$.fn.hAlign = function() {
return this.each(function(i){
var w = $(this).width();
var ow = $(this).outerWidth();
var ml = (w + (ow - w)) / 2;
$(this).css("margin-left", "-" + ml + "px");
$(this).css("left", "50%");
$(this).css("position", "absolute");
});
};
})(jQuery);
最佳答案
要做到这一点,您有很多变体。在您的情况下,您可以这样做
<div style="
background: url('Assets/OrderSheet.png') center center no-repeat;
width: 100%;
height: 500px;
">
<a href="Assets/OrderSheet.xls">
</a>
</div>
关于javascript - 自动对齐脚本在页面加载时不对齐,但在刷新时不对齐?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16977166/