#popup_image {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 1400px;
z-index: 201;
display: none;
background-repeat: no-repeat;
background-position: center center;
background-image: url(images/fullgraphic3.jpg);
}
<div id="popup_image">
</div>
我希望这样...... Spoon Graphics
无论您点击哪个缩略图或您在页面的下方,它都是相对于浏览器窗口的位置,但滚动时图像也不会滚动。
答案 0 :(得分:0)
function center(divid) {
$(divid).css("position","absolute");
$(divid).css("top", (($(window).height() - $(divid).outerHeight()) / 2) + $(window).scrollTop() + "px");
$(divid).css("left", (($(window).width() - $(divid).outerWidth()) / 2) + $(window).scrollLeft() + "px");
return this;
}
使用方法:
center("#divid");
答案 1 :(得分:0)
你可以像这样居中div:
<强> CSS 强>
.popup {
background:#AAA;
display:inline;
float:left;
height:100px;
position:fixed;
width:auto;
z-index:9999;
}
<强> JS 强>
$(function PopUp(){
$('.popup').each(function(){
$(this).css('left',($(window).width()-$(this).outerWidth())/ 2 + 'px');
$(this).css('top',($(window).height()-$(this).outerHeight())/ 2 + 'px');
});
});