I'm displaying some images on a webpage and I want it to be scrolled all the way to the bottom as soon as the page loads, then fade the image in. This is what my code looks like thus far:
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script>
$(document).ready(function(){
// fade in initial image
$("#lower").fadeIn(3000);
$("#lower").css("display", "block;");
// show only initial image at mid-page
var margin = ( $(window).height() - $("#lower").height() ) * (0.5);
$("#lower").css("margin-top", margin);
// set scroll position to bottom of page
$(document).scrollTop( $(document).height() );
});
</script>
and my html looks like this:
<body>
<div id="view">
<img id="upper" src="pages/2.gif">
<img id="lower" src="pages/1.gif">
</div>
</body>
(#upper has opacity 0 and I plan to fade it in later, when the user scrolls up to the image)
the problem I'm having is that the page doesn't scroll all the way to the bottom on load. Ive tried a number of things including changing the selector for the .scrollTop function to body and/ or html tag as well as document or window. I even tried overshooting the scrollTop value excessively but to no avail.
Can anyone tell me me why The page is not scrolling all the way to the bottom upon load?
[EDIT] Sorry sorry, sloppy code. Finals week and little sleep. Heres a no-typo version of the same thing with the same problem. I even overshot the scrollTop parameter here, but the result is the same.
An observation: scroll location persists after refresh. Could this have anything to do with the obstinate scroll position here?