Flash made with buffered scroll bar

Source: Internet
Author: User

The effect is as follows:

Click here to download the source file

The normal scroll bar looks stiff when the content is moving, how does it make it look comfortable? Plus a cushion! This will look very smooth and comfortable.

There are only two components and one dynamic text box (in order to be able to use the mask to embed the font):
1, slide block, instance name Move_bar;
2, a mask element, used to control the size of the display content area, instance name mask;
3, the dynamic text instance is named TXT.
Here is the code, written on the hardwood on the line.

First define the move range of the slider
Barup = 67;
Bardown = 204;
Barpos = 446;
And then the degree of buffering, the greater the speed value, the more obvious the buffer.
Speed = 6;
And then this is the ratio of calculation, which is the ratio of the sliding slot to the movable length of the content
Prop = (txt._height-mask._height)/(Bardown-barup);
Record the initial position of the content
Txtorigin = txt._y;
Start dragging when pressed on the slider, down to determine whether to drag
move_bar.onpress = function () {
Move_bar.startdrag (0, Barpos, Barup, Barpos, Bardown);
down = 1;
};
Stop dragging when mouse is loose, down to 0
Move_bar.onmouseup = function () {
Move_bar.stopdrag ();
down = 0;
};
This is the key, Enterframe plus if (down), which is to keep executing the if inside of the program while dragging
This.onenterframe = function () {
if (down) {
The Y value of the slider at this point subtracts the upper limit of the slider, calculates the distance that the slider moves downward, times the calculated proportions, and gets the distance that the text content should be moved up.
Txtmove = (Move_bar._y-barup) *prop;
The original position minus the distance, to get the text content should now be in position, that is, the target location
txt.m_y = Txtorigin-txtmove;
}
Each variable of the Y value of the text content = (target position-current position) divided by buffer speed. Note that this sentence cannot be placed inside the if loop, otherwise the mouse will stop as soon as the buffer is released.
Txt._y + = (txt.m_y-txt._y)/speed;
}; OK, test, don't forget to set the number of frames a little higher (I use 48), so that looks smooth. The code takes into account the ease of use, in other places, only need to change the scope of the slide block, set the various components of the instance name can be.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.