본문 바로가기

레이어 중앙 위치

web/javascript by 낼스 2019. 8. 1.
##### [source : https://jsfiddle.net/softm/5fdqa0ho/](https://jsfiddle.net/softm/5fdqa0ho/) ##### # init ```javascript function init() { var obj = document.all['test']; var w = parseFloat(obj.style.width); var h = parseFloat(obj.style.height); //alert (w + ' / ' + h ); //alert ( document.body.scrollTop ); var aw = parseFloat(document.body.clientWidth); var ah = parseFloat(document.body.clientHeight); //alert (aw + ' / ' + ah ); var t = (ah - h) / 2; var l = (aw - w) / 2; //alert (t + ' / ' + l); obj.style.top = t + parseFloat(document.body.scrollTop); obj.style.left = l + parseFloat(document.body.scrollLeft); //alert (obj.style.top + ' / ' + obj.style.left); } window.attachEvent('onload',init); window.attachEvent('onresize',init); ``` ##### # html ```html
중앙
```

'web > javascript' 카테고리의 다른 글

Javascript SnakBar  (0) 2019.08.06
show loading progress image  (0) 2019.08.05
ECMA6  (0) 2019.07.27
date time random  (0) 2019.07.26
Node.js - Http Module  (0) 2019.07.24

댓글