jquery实现水平垂直居中
更新:HHH   时间:2023-1-7


jquery实现元相对于窗口水平垂直居中:
 
$(document).ready(function(){
 $(
'.className').css({
  position:
'absolute',
  left: ($(window).width() 
- $('.className').outerWidth())/2,
   top: ($(window).height() - $('.className').outerHeight())/2 + $(document).scrollTop()
 });
});
 

css实现元素水平垂直居中:

.class{

 width:300px;

height:400px;

position:absolute;

left:50%;

top:50%;

margin:-200px 0 0 -150px;

}



 

返回web开发教程...