通过使用jQuery,我将div垂直放置在窗口的中心位置。此脚本不支持$(document).ready(function(),但仅在调整窗口大小后才开始工作。
我需要的是工作,而加载页面,第一时间itself.Refer小提琴
HTML:
<div class="welcomer">
<center>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
</center>
</div>
CSS:
body {
background: #ccc;
color:#000;
}
.welcomer {
width: 100%;
background: #fff;
}
jQuery的
$(document).ready(function(){
$(window).resize(function(){
$('.welcomer').css({
position:'absolute',
"top": ((($(window).height() - $('.welcomer').outerHeight()) / 2) + $(window).scrollTop() + "px"),
"left": ((($(window).width() - $('.welcomer').outerWidth()) / 2) + $(window).scrollLeft() + "px")
});
// To initially run the function:
$(window).resize();
});
看起来像您$(window).resize()
在调整大小处理程序中调用
$(document).ready(function () {
$(window).resize(function () {
$('.welcomer').css({
position: 'absolute',
"top": ((($(window).height() - $('.welcomer').outerHeight()) / 2) + $(window).scrollTop() + "px"),
"left": ((($(window).width() - $('.welcomer').outerWidth()) / 2) + $(window).scrollLeft() + "px")
});
}).resize(); // To initially run the function:
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句