JQuery/javascript - Center a div within an iframe view area. scrollTop not accurate with iframe height adjusted?

I could not get this resolved but I figure I would write what I did to work around this. I put the div I wanted centered on the page that holds the iframe as well as the centerdiv function. Then in the my code inside the iframe I did the following.

Up vote 0 down vote favorite share g+ share fb share tw.

Ok normally this would be easy but for visual reasons I force my iframe to be the same height as the content it contains. What this does is gives me only one scroll bar, the scroll bar on the parent window. The iframe document never scrolls.

The problem comes when I try to center a div within the iframe. When the page is scrolled a couple of pages down I cannot get an accurate scrolltop value. $(window).scrollTop() is always zero.

If I use parent.document.documentElement. ScrollTop instead of $(window).scrollTop() I get a value but it is completely out to lunch. For example if iframe's height is 2011 and I scroll to the bottom of the iframe and I query parent.document.documentElement.

ScrollTop I get a value 567 returned. My screen size is 1200 Same results in all browsers. Tested latest IE, FF, Opera, Chrome.

To simulate in outerdoc. Htm I have doc1. Htm: my title 10 pages of content near the bottom show div jquery iframe div center scrolltop link|improve this question asked Aug 12 '10 at 16:42ethermal463.

Have you tried doing it without the iframe?... seems unnecessary at first glance.. – Fosco Aug 12 '10 at 16:49 yes works fine without the iframe but the iframe is necessary. – ethermal Aug 13 '10 at 12:33.

I could not get this resolved but I figure I would write what I did to work around this. I put the div I wanted centered on the page that holds the iframe as well as the centerdiv function. Then in the my code inside the iframe I did the following.

Function CenterDiv(item) { if (window. Location! = window.parent.

Location) parent. CenterDiv(item); }.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions