position.js 995 B

12345678910111213141516171819202122232425262728293031
  1. /* http://textsnippets.com/posts/show/835 */
  2. Position.GetWindowSize = function(w) {
  3. w = w ? w : window;
  4. var width = w.innerWidth || (w.document.documentElement.clientWidth || w.document.body.clientWidth);
  5. var height = w.innerHeight || (w.document.documentElement.clientHeight || w.document.body.clientHeight);
  6. return [width, height];
  7. };
  8. /* http://textsnippets.com/posts/show/836 */
  9. Position.Center = function(element, parent) {
  10. var w, h, pw, ph;
  11. var d = Element.getDimensions(element);
  12. w = d.width;
  13. h = d.height;
  14. Position.prepare();
  15. if (!parent) {
  16. var ws = Position.GetWindowSize();
  17. pw = ws[0];
  18. ph = ws[1];
  19. } else {
  20. pw = parent.offsetWidth;
  21. ph = parent.offsetHeight;
  22. }
  23. element.style.top = (ph/2) - (h/2) - Position.deltaY + "px";
  24. element.style.left = (pw/2) - (w/2) - Position.deltaX + "px";
  25. };