Hi Colin,

The dimensions plugin was recently added to the jQuery core, and you
can combine with the plain javascript window.scrollTo method to do
what you want.

Here is a little plugin I whipped up:

<script language="javascript" type="text/javascript">
$(document).ready(function(){
   $.fn.extend({
      showAndScroll: function() {
         $(this).show();
         if( $(this).position()['top'] )
            window.scrollTo(0, $(this).position()['top']);
         }
   });
});
</script>

Now whenever you want to display it, call:

   $('someSelector).showAndScroll();

There are a couple of considerations. I haven't tested this
thoroughly, so not sure how it handles positioning within positions
divs, cross browser issues etc. Also, don't forget that this will
scroll so the target element is at the top of the page - but you could
always add an offset, or change the target you're scrolling to.

Have fun!

On Jun 17, 9:08 am, Colin Manning <[EMAIL PROTECTED]> wrote:
> Hi
>
> Newbie user and I guess this probably has a simple answer.
>
> I have a hidden div on the page that is shown when user clicks a button.
> Its a help text, in a div, for the page that is only to be shown when the
> user wants it. But the page is long and when I un-hide the div I also want
> the browser to scroll the document so as to ensure this div actually
> visible within the browser window.
>
> Is there an easy way in jQuery to ensure a given element is actually
> visible on screen and not scrolled off the bottom?
>
> Thanks
> Colin
>
> --
> No virus found in this outgoing message.
> Checked by AVG.
> Version: 7.5.523 / Virus Database: 270.3.0/1503 - Release Date: 14/06/2008 
> 18:02

Reply via email to