>  기사  >  웹 프론트엔드  >  페이지 높이와 스크롤 막대 위치를 가져오는 자바스크립트 코드_javascript 기술

페이지 높이와 스크롤 막대 위치를 가져오는 자바스크립트 코드_javascript 기술

WBOY
WBOY원래의
2016-05-16 18:27:59961검색
复제대码 代码如下:

var Viewport={
top : function(){
return window.pageYOffset
|| document.documentElement && document.documentElement.scrollTop
|| document.body.scrollTop;
},
height : function(){
return window.innerHeight
|| document.documentElement && document.documentElement.clientHeight
|| document.body.clientHeight;
},
left : function(){
return window.pageXOffset
|| document.documentElement && document.documentElement.scrollLeft
|| document.body.scrollLeft;
},
width : function(){
return window.innerWidth
|| document.documentElement && document.documentElement.clientWidth
|| document.body.clientWidth;
},
right : function(){
return Viewport.left() Viewport.width();
},
bottom : function(){
return Viewport.top() Viewport.height();
}
};


居中:
复代码 代码如下:

style.position="절대";
style.left=50%;
style.top=Viewport.Top() Viewport.Height()/2 "px";
성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.