Alternative "scrollIntoView"

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • xevi.matavacas@gmail.com

    Alternative "scrollIntoView"

    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 alternativeScro llIntoView(pare ntDiv,elementIn toDiv)
    {
    var principal =parentDiv;
    principal.scrol lTop = 0;
    var rects = principal.getCl ientRects()[0];
    var topFinal = rects.top;
    var bottomFinal = rects.bottom;
    var bottomActual = elementIntoDiv. getClientRects( )[0].bottom;
    if (bottomActual == 0)
    {
    return;
    }
    while(bottomAct ual>bottomFinal ||bottomActual< topFinal)
    {
    var direction="down ";
    if(bottomActual <topFinal) direction="up";
    principal.doScr oll(direction);
    bottomActual=el ementIntoDiv.ge tClientRects()[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.

  • RobG

    #2
    Re: Alternative &quot;scrollInt oView&quot;

    xevi.matavacas@ gmail.com wrote:[color=blue]
    > 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:[/color]

    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

    Comment

    • xevi.matavacas@gmail.com

      #3
      Re: Alternative &quot;scrollInt oView&quot;

      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.

      Comment

      • RobG

        #4
        Re: Alternative &quot;scrollInt oView&quot;

        xevi.matavacas@ gmail.com wrote:[color=blue]
        > 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.
        >[/color]

        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

        Comment

        • xevi.matavacas@gmail.com

          #5
          Re: Alternative &quot;scrollInt oView&quot;

          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.

          Comment

          Working...