javascript - Automatic scrolling on load to show all of a page -


i have jsfiddle here - http://jsfiddle.net/stevea/z3yvt/ - absolutely positioned orange box:

div#box2 {     width:150px;     height: 150px;     background-color:orange;     border:1px solid black;     position:absolute;     top:-50px;     right:400px; } 

currently box offset 50px above top of page, see bottom 100px of 150px box. page load automatically scrolls show of box. possible?

thanks

have considered animate?

fiddle


you can't scroll page, can scroll objects in page; or perhaps want scroll body:

$('body').css('position','relative').animate({top:'50px'}) 

fiddle


using new criteria, want scan offsets of elements , adjust accordingly:

var min = { top: 0, $el: {} };  // scan elements $('body *').each(function () {     var $this = $(this),         _top = $this.offset().top;      if (_top < min.top) {         min.top = _top;         min.$el = $this;     } });  // adjust accordingly $('body').css('position', 'relative').animate({     top: (min.top * -1) + 'px' }) 

fiddle


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -