GithubHelp home page GithubHelp logo

kenny-ngo / slim-scroll Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kamlekar/slim-scroll

0.0 1.0 0.0 153 KB

HTML element scroll bar as replacement for default browser's scroll-bar. Design as you want using CSS.

License: MIT License

HTML 48.31% CSS 4.56% JavaScript 47.13%

slim-scroll's Introduction

Slim-scroll (JavaScript Scroll Library) ~ 4KB compressed

Slim scroll is a replacement of default scrollbar provided by browsers on Windows. This library lets you design the scroll-bar by using simple css properties. It is created using javascript and css.

Download  |  Github  |  Demo   |   CDNjs

Tested on: IE9+, Chrome and Firefox.

Main Features:

  • Easier to color the custom scrollbar using CSS.
  • Can animate easily (check below properties for support).
  • Re-evaluates when the container is fluid, vertically.

How to use:

  • To make it work, include slimscroll.js in head tag.
  • Apply height to the container in fixed units or percentage.
  • Just design the scrollbar as you want by applying css classes as explained below.
  • [In IE8] Apply high specificity to override normal styles given to the scroll bar.

and then:

Method 1 (with no added styles):
new slimScroll(Element);   // 'Element' is Javascript DOM object
Method 2 (with added styles):

or to add your own defined css styles:

new slimScroll(Element, {
  'wrapperClass': '',

  'scrollBarClass': '',

  'scrollBarContainerClass': '',  

  'scrollBarContainerSpecialClass': '',

  'scrollBarMinHeight': '',

  'scrollBarFixedHeight': '',

  'keepFocus': true/false
});
Explanation of above properties:
  • wrapperClass (type - "string") : Mention wrapper class here.
  • scrollBarClass (type - "string") : Mention scroll bar class here.
  • scrollBarContainerClass (type - "string") : Mention scroll bar container class here.
  • scrollBarContainerSpecialClass (type - "string") : This property is used to mention a class which will be applied only when the user is scrolling the content. Could be helpful while applying animations to the scroll bar.
  • scrollBarMinHeight (type - "Integer") : Used to mention minimum scroll bar height here (without pixel unit)
  • scrollBarFixedHeight (type - "Integer") : Used to mention scroll bar fixed height (without pixel unit). This makes sure to show the scroll bar height fixed even when content inside the container is increased.
  • keepFocus (type - "Boolean") : Used to focus the container.

To make this work on height resize:

var customScroll = new slimScroll();
window.onresize = customScroll.resetValues;  // pure javascript example.

Note:

  • Usage of the above mentioned properties is optional or as per need.
  • Add higher specificity css to override the custom styles which are being applied by this library.
  • Don't override the styles which are given highest specificity (!important) by this library (those styles are necessary to make this scroll library work).

How I got this thought:

I got this thought, when I found solution to hide the default scrollbar (using css) which was the requirement for a post on Stackoverflow.

The solution was simple but that is how I got this thought :).

Future implementations:

  • Implement Horizontal Scrollbar.

If you find any issue(s), please file here.

slim-scroll's People

Contributors

kamlekar avatar scottbeeson avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.