Set the scroll bar in the DIV to a random position (CSS + JavaScript)

Source: Internet
Author: User

Just now, a friend told me that his blog has too many links, so he put all the links in a div and added a scroll bar, but he didn't want to see them every time, I saw the previous links, so I asked if I could do anything. I thought of a solution.

The style is used to limit the DIV style and add a scroll bar.
The key is actually very simple. The last two lines of JavaScript work only on the last line:
OBJ. scrolltop = obj. scrollheight * (math. Random ());
OBJ. scrolltop: the position of the scroll bar from the top
OBJ. scrollheight: the height of the flow area
Math. Random (): obtain a random number.
It's very simple. Someone may need it. Take it for use. Haha

PS: IE6/IE7/ff2 passed the test
During the local test of IE7, the position of the scroll bar is different only when it is opened each time, but the refresh is not changed, but it will be normal after it is placed on the website.

CodeAs follows:

< Div ID = "Cc" Style = "Height: 250px; width: 200px; overflow-Y: Scroll; overflow-X: hidden ;" >
< Li > 01 </ Li > < Li > 02 </ Li > < Li > 03 </ Li > < Li > 04 </ Li > < Li > 05 </ Li > < Li > 06 </ Li > < Li > 07 </ Li > < Li > 08 </ Li >
< Li > 09 </ Li > < Li > 10 </ Li > < Li > 11 </ Li > < Li > 12 </ Li > < Li > 13 </ Li > < Li > 14 </ Li > < Li > 15 </ Li > < Li > 16 </ Li >
< Li > 17 </ Li > < Li > 18 </ Li > < Li > 19 </ Li > < Li > 20 </ Li > < Li > 21 </ Li > < Li > 22 </ Li > < Li > 23 </ Li > < Li > 24 </ Li >
< Li > 25 </ Li > < Li > 26 </ Li > < Li > 27 </ Li > < Li > 28 </ Li > < Li > 29 </ Li > < Li > 30 </ Li > < Li > 31 </ Li > < Li > 32 </ Li >
< Li > 33 </ Li > < Li > 34 </ Li > < Li > 35 </ Li > < Li > 36 </ Li > < Li > 37 </ Li > < Li > 38 </ Li > < Li > 39 </ Li > < Li > 40 </ Li >
< Li > 41 </ Li > < Li > 42 </ Li > < Li > 43 </ Li > < Li > 44 </ Li > < Li > 45 </ Li > < Li > 46 </ Li > < Li > 47 </ Li > < Li > 48 </ Li >
</ Div >
< Script >
VaR OBJ = Document. getelementbyid ( " CC " );
OBJ. scrolltop = OBJ. scrollheight * (Math. Random ());
</ Script >
Related Article

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.