I am using this code to center myDiv to active screen. (taken from Using jQuery to center a DIV on the screen)
$("#myDiv").css("position","absolute");
$("#myDiv").css("top", Math.max(0, (($(window).height() - $("#myDiv").outerHeight()) / 2) + $(window).scrollTop()) + "px");
$("#myDiv").css("left", Math.max(0, (($(window).width() - $("#myDiv").outerWidth()) / 2) + $(window).scrollLeft()) + "px");
Code works perfectly if the page is loaded in browser window and correctly centered the myDiv to active screen (ignoring the length of page no matter I am having lots of scrolling down or above).
But when the page is loaded within iframe then the code is not working as per expectations and centers the DIV (vertically) according to complete length of content (not the active screen). So if I am at the top of screen and page is let say 3000px long then the code will show the myDiv down there at 1500px, where as if page is loaded in browser window then myDiv will be shown according to whatever is the current active screen/scroll position.
I want to center the div as per the current active screen/scroll. No matter page is loaded in browser window or the iframe. Any help?
Thanks in advance,