0

i was able to find a good script on centering a div vertically but not compatible on ie old browser and another issue my div is pushing up because i have a footer and i dont know how to adjust on script adding a top border :(

<script type="text/javascript">
		<!--
		function getWindowHeight() {
			var windowHeight = 0;
			if (typeof(window.innerHeight) == 'number') {
				windowHeight = window.innerHeight;
			}
			else {
				if (document.documentElement && document.documentElement.clientHeight) {
					windowHeight = document.documentElement.clientHeight;
				}
				else {
					if (document.body && document.body.clientHeight) {
						windowHeight = document.body.clientHeight;
					}
				}
			}
			return windowHeight;
		}
		function setContent() {
			if (document.getElementById) {
				var windowHeight = getWindowHeight();
				if (windowHeight > 0) {
					var contentElement = document.getElementById('content');
					var contentHeight = contentElement.offsetHeight;
					if (windowHeight - contentHeight > 0) {
						contentElement.style.position = 'relative';
						contentElement.style.top = ((windowHeight / 2) - (contentHeight / 2)) + 'px';
					}
					else {
						contentElement.style.position = 'static';
					}
				}
			}
		}
		window.onload = function() {
			setContent();
		}
		window.onresize = function() {
			setContent();
		}
		//-->
		</script>
1
Contributor
1
Reply
2
Views
5 Years
Discussion Span
Last Post by Julia25
0

i found a better script which are compatible with old ie
is it possible to adjust alignment to be a little not and not too center because of the footer

<script type="text/javascript">

$(function() {
  $.fn.verticalCenter = function() {
    $(this).each(function() {
      $pageCenter = $(this).height() / 2;
      $windowCenter = $(window).height() / 2;
      $top = $windowCenter - $pageCenter;
      $(this).css({
        'position': 'relative',
        'top' : $top + 'px'
      });
    });
  }
  myResize = function() {
	  
	  
	    
	  
   $('#content:visible').verticalCenter();
  }
  $(window).resize(myResize);
  myResize();
});


</script>

Edited by Julia25: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.