Ease Scroll...

January 6th, 2009
  • how would I change this code:


    up_arrow.onRelease = function() {
    form.body_txt.scroll--;
    };

    down_arrow.onRelease = function() {
    form.body_txt.scroll++;
    };


    ...so that the scrolling eases. I am assuming that you would instead of say "++" you would assign a number like 3 and then divide the number by the ending point. But, even though that sounds simple enough, I'm not sure how to apply it in this sense.

    Thanks


  • You would want to check the distance from the "end point", such as the top of the page if scrolling up. Then you would apply a physics variable of friction to the movement. For example:

    var friction = .6;
    up_arrow.onRelease = function(){
    var dist = this._y;
    var velY = dist * velY;
    }

    With this code, your scrolling content will change drastically if it is further away, but will get the easing effect. To force it to scroll at a certain speed until it reaches a certain point, or, to have it continue to scroll after the button is pressed, assign an onEnterFrame when the button is released, and then continually divide a predefined distance variable by the friction:

    var friction = .6;
    var distToScroll = 5;
    up_arrow.onRelease = function(){
    this.remainingDistance = distToScroll;
    this.onEnterFrame = function(){
    if(this.remainingDistance <= 1){
    delete this.onEnterFrame;
    } else {
    this.remainingDistance *= _root.friction;
    this._y -= this.remainingDistance;
    }
    };
    }


    Hope that makes sense...







  • #If you have any other info about this subject , Please add it free.#
    Your name:
    E-mail:
    Telphone:

    Your comments:


    If you have any other info about Ease Scroll... , Please add it free.