[Javascript] Auto scrolling

Hassan Schroeder hassan at webtuitive.com
Thu Feb 13 14:54:26 CST 2003


Larry Cotton wrote:
> Hi
> 
> I've written a contents page that displays/hides sub-section titles when 
> you click on a section title. This is done by using the 'display' style 
> property. The problem is whenever you 'open up' a list of sub sections 
> the browser automatically scrolls to the top of the screen, so you have 
> to scroll down to see the newly displayed sub sections.
> 
> Does anyone know how to prevent this scrolling to the top ?

Yes -- don't tell it to :-)

Most browsers react to a non-existent anchor href ("#") by jumping
to the top of the page. Have your onclick function return false to
prevent the href target from being used:

<div id="Intro" style="display: '';" onClick="return(controlExpand(this, > 2));">
<a href="#" style="color: white; font-size: > 24pt;">Introduction</a></div>

function controlExpand(obj, noOfKids)
{
     // actions deleted for brevity

     return false;
}

HTH!
-- 
Hassan Schroeder ----------------------------- hassan at webtuitive.com
Webtuitive Design ===  (+1) 408-938-0567   === http://webtuitive.com

                           dream.  code.






More information about the Javascript mailing list