Alternative "scrollIntoView"

Discussion in 'Javascript' started by xevi.matavacas@gmail.com, Dec 30, 2005.

  1. Guest

    Hi friends,

    I found a problem while "scrolling into view" and to overcome this I
    made a function to simulate javascript's function. I would like to
    share it and here it is:

    function alternativeScrollIntoView(parentDiv,elementIntoDiv)
    {
    var principal =parentDiv;
    principal.scrollTop = 0;
    var rects = principal.getClientRects()[0];
    var topFinal = rects.top;
    var bottomFinal = rects.bottom;
    var bottomActual = elementIntoDiv.getClientRects()[0].bottom;
    if (bottomActual == 0)
    {
    return;
    }
    while(bottomActual>bottomFinal||bottomActual<topFinal)
    {
    var direction="down";
    if(bottomActual<topFinal) direction="up";
    principal.doScroll(direction);
    bottomActual=elementIntoDiv.getClientRects()[0].bottom;
    }
    }

    It worked in my enviroment, i hope it could be useful for you too.

    Xevi.

    PS: It was done for IE. I didn't test it in other enviroments.
    , Dec 30, 2005
    #1
    1. Advertising

  2. RobG Guest

    wrote:
    > Hi friends,
    >
    > I found a problem while "scrolling into view" and to overcome this I
    > made a function to simulate javascript's function. I would like to
    > share it and here it is:


    What version of IE supports getClientRects() and doScroll() but not
    scrollIntoView()? Doesn't scrollIntoView() go back to IE 4 and the
    other two to IE 5?


    [...]


    --
    Rob
    RobG, Dec 30, 2005
    #2
    1. Advertising

  3. Guest

    All of these functions worked on IE5.5 but the result was not always
    the expected. Sometimes the element didn't fit into the view. That's
    why we made this function to overcome this.
    , Dec 30, 2005
    #3
  4. RobG Guest

    wrote:
    > All of these functions worked on IE5.5 but the result was not always
    > the expected. Sometimes the element didn't fit into the view. That's
    > why we made this function to overcome this.
    >


    A more cross-browser function could use scrollIntoView first, then
    adjust the position using your function if the features are supported
    (of course scrollIntoView should be feature tested too).

    That may also provide some extra speed/efficiency on IE where the
    element needs to scroll a long way.


    --
    Rob
    RobG, Dec 30, 2005
    #4
  5. Guest

    You're right, I agree that this is the best option. Better use first
    what the enviroment provides and if necessary use the function I made.

    Thanks a lot.
    , Dec 30, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Larry Brown

    scrollIntoView called on postback

    Larry Brown, Feb 28, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    742
    Larry Brown
    Feb 28, 2005
  2. da_rod_father
    Replies:
    1
    Views:
    1,922
    tullio-ballarino
    Nov 14, 2006
  3. F. Da Costa
    Replies:
    1
    Views:
    109
    F. Da Costa
    Jan 21, 2004
  4. bjarthur

    safari and scrollIntoView

    bjarthur, Feb 25, 2005, in forum: Javascript
    Replies:
    1
    Views:
    166
    Zifud
    Feb 25, 2005
  5. cmay
    Replies:
    3
    Views:
    279
Loading...

Share This Page