function centerposition( obj ){ var wWidth = document.documentElement.clientwidth; var wHeight = document.documentElement.clientHeight; var oWidth = obj.offsetWidth; var oHeight = obj.offsetHeight; obj.style.left = (wWidth - oWidth) / 2 + ‘px‘; obj.style.top = (wHeight - oHeight) / 2 + ‘px‘; }
原文:http://www.cnblogs.com/fuxiang-yang/p/4925799.html