1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.
  2. Better Analytics for WordPress Get It Free

How can I make the page auto-scroll to its end

Discussion in 'JavaScript' started by AHA7, Jun 23, 2007.

  1. #1
    Hello,

    I have a web page with many items on it, it takes a while for it to completely load and it takes a lot of vertical scrolling from the head to the foot of the page.
    The problem is that the vertical scroll bar would stick at the top of the page and not scroll down when new items are loaded to the window (page not completely received yet).

    How can I make the vertical scroll bar auto-scroll to the end of the page while new items are being added to the page during the loading process?

    I use IE 6.
     
    AHA7, Jun 23, 2007 IP
  2. ajsa52

    ajsa52 Well-Known Member

    Messages:
    3,427
    Likes Received:
    125
    Best Answers:
    0
    Trophy Points:
    160
    #2
    Supposing your HTML code is loaded first and then the images, you can use somethign like this:
    
    <html>
    <head>
      <script type="text/javascript">
      function moveWin()
      {  
        window.scroll(0,10000);
        setTimeout('moveWin();',1000);
      }
      </script>
    </head>
    <body onLoad="moveWin();">
      <!-- many pictures -->
    </body>
    </html>
    
    Code (markup):
    If you have a huge HTML, that method won't work, so you need to use frames or iframes.
     
    ajsa52, Jun 23, 2007 IP
  3. UnrealEd

    UnrealEd Peon

    Messages:
    148
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #3
    or you can place a named link at the bottom of your page, and change the href.location value to point to that anchor:
    <html>
    <head>
      <script type="text/javascript">
    function pointToBottom(){
      window.href.location = "this_page.html#bottomlink";
    }</script>
    </head>
    <body onLoad="pointToBottom()">
    <!-- page here -->
    <a name="bottomlink">&nbsp;</a>
    </body>
    </html>
    HTML:
    this might refresh your page though, but i'm not sure :)
     
    UnrealEd, Jun 23, 2007 IP
  4. glasglow

    glasglow Active Member

    Messages:
    926
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #4
    Here is what I use.. it's just autoscroll.. you can play with the division factors to get a different time.

    <SCRIPT language=JavaScript1.2>
    //change 1 to another integer to alter the scroll speed. Greater is faster
    var speed=1
    var currentpos=0,alt=1,curpos1=0,curpos2=-1
    function initialize(){
    startit()
    }
    function scrollwindow(){
    if (document.all &&
    !document.getElementById)
    temp=document.body.scrollTop
    else
    temp=window.pageYOffset
    if (alt==0)
    alt=2
    else
    alt=1
    if (alt==0)
    curpos1=temp
    else
    curpos2=temp
    if (curpos1!=curpos2){
    if (document.all)
    currentpos=document.body.scrollTop+speed
    else
    currentpos=window.pageYOffset+speed
    window.scroll(0,currentpos)
    }
    else{
    currentpos=0
    window.scroll(0,currentpos)
    }
    }
    function startit(){
    setInterval("scrollwindow()",400)
    }
    window.onload=initialize
    </SCRIPT>
     
    glasglow, Jun 27, 2007 IP