Javascript custom scroll bar implementation code

Source: Internet
Author: User
This article mainly introduces the javascript custom scroll bar implementation code, which has a certain reference value. Interested friends can refer to the content that is often encountered in the work that will go beyond a fixed range, the content that exceeds the limit is generally displayed in a scroll bar.

However, the default browser scroll bar is often despised by the product manager, but css cannot change the style of the scroll bar. Fortunately, there is a omnipotent js scroll _^ ~~

There are a variety of plug-ins on the Internet, but the best thing is to write it yourself. You can also learn it while learning it by yourself (* ^__ ^ *)

These three problems have deeply plagued me:

1. Scroll Bar Height

2. How long should the scroll bar move every time you click the up or down button?

3. How much do I need to move the page every time I drag the 1px scroll bar?

The entire framework is like this:

The complete demo code is as follows:

Note: Because seajs is used, pay attention to file loading.

Css:

.wapper{scrollbar-3dlight-color:#000; position:relative; height:302px;width:300px;overflow:hidden;margin:0 auto;line-height:40px;text-align:center;} .area{background-color:#E2E2EF;width:100%; position:absolute;top:0px;left:0px;} .bar{position:absolute;top:0px;right:0px; height:100%;width:1rem;background-color:#ccc;} .scroll,.middle,.forward,.backward{display:block;cursor:pointer;position:absolute;right:0px;width:100%;} .forward,.backward{height:16px;background-color:#6868B1;} .middle{background-color:rgba(255, 255, 255, 0.22);top:16px;cursor:auto;} .scroll{position:absolute;top:0px;background-color:#C2C2E9;} .forward{top:0px;} .backward{bottom:0px;}

Html:

1. this is content

2. this is content

3. this is content

4. this is content

5. this is content

6. this is content

7. this is content

8. this is content

9. this is content

10. this is content

11. this is content

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.