Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
simplebar
Advanced tools
SimpleBar is a custom scrollbar library that aims to provide a simple and lightweight solution for creating custom scrollbars that look consistent across different browsers and platforms. It allows you to style the scrollbar to match your application's design while maintaining native scrolling performance.
Custom Scrollbars
SimpleBar allows you to create custom scrollbars by adding a `data-simplebar` attribute to your HTML elements. This will replace the default scrollbar with a custom one that you can style using CSS.
<div data-simplebar style="max-height: 300px;">
Your content here
</div>
Auto-Hiding Scrollbars
You can control the auto-hide behavior of the scrollbar by setting the `data-simplebar-auto-hide` attribute to `false`. This will keep the scrollbar visible at all times.
<div data-simplebar-auto-hide="false" style="max-height: 300px;">
Your content here
</div>
RTL Support
SimpleBar supports right-to-left (RTL) text direction. You can enable this by setting the `data-simplebar-direction` attribute to `rtl`.
<div data-simplebar-direction="rtl" style="max-height: 300px;">
Your content here
</div>
Custom Scrollbar Styles
You can customize the appearance of the scrollbar by targeting the `.simplebar-scrollbar` class in your CSS. This allows you to change the color, width, and other styles of the scrollbar.
<style>
.simplebar-scrollbar::before {
background-color: #3498db;
}
</style>
<div data-simplebar style="max-height: 300px;">
Your content here
</div>
Perfect Scrollbar is a similar library that provides custom scrollbars with a focus on performance and simplicity. It offers more customization options and better support for touch devices compared to SimpleBar.
React Custom Scrollbars is a React-specific library for creating custom scrollbars. It provides a more React-friendly API and better integration with React applications compared to SimpleBar.
SimpleBar is a plugin that tries to solve a long time problem : how to get custom scrollbars for your web-app?
SimpleBar does NOT implement a custom scroll behaviour. It keeps the native overflow: auto
scroll and only replace the scrollbar visual appearance.
SimpleBar is meant to be as easy to use as possible and lightweight. If you want something more advanced I recommend https://github.com/noraesae/perfect-scrollbar
- Via npm
npm install simplebar --save
Then don't forget to import both css and js in your project.
- Via <script>
tag
<link rel="stylesheet" href="https://unpkg.com/simplebar@latest/dist/simplebar.css" />
<script src="https://unpkg.com/simplebar@latest/dist/simplebar.js"></script>
<!-- or -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/simplebar@latest/dist/simplebar.css">
<script src="https://cdn.jsdelivr.net/npm/simplebar@latest/dist/simplebar.js"></script>
note: you can replace @latest
to the latest version (ex @2.4.3
), if you want to lock to a specific version
- For Ruby On Rails
To include SimpleBar in the Ruby On Rails asset pipeline, use the simplebar-rails gem.
Set data-simplebar
on the element you want your custom scrollbar. You're done.
<div data-simplebar></div>
SimpleBar is not intended to be used on the body
element! I don't recommend wrapping your entire web page inside a custom scroll as it will often affect badly the user experience (slower scroll performances compare to native body scroll, no native scroll behaviours like click on track, etc.). Do it at your own risk!
SimpleBar is meant to improve the experience of internal web pages scroll: like a chat box or a small scrolling area.
You can start SimpleBar mannually if you need to:
new SimpleBar(document.getElementById('myElement'))
If you want to use jQuery:
new SimpleBar($('#myElement')[0])
Options can be applied to the plugin during initialization:
new SimpleBar(document.getElementById('myElement'), {
option1: value1,
option2: value2
})
Available options are:
By default SimpleBar requires minimal markup. When initialized it will wrap a simplebar-content
element in a div with the class simplebar-scroll-content
. If you prefer to include this wrapper element directly in your markup you can switch the default behaviour off by setting the wrapContent
option to false
:
new SimpleBar(document.getElementById('myElement'), { wrapContent: false });
Default value is true
:warning: this option is deprecated and shouldn't be needed anymore (just prepare your DOM as you want and it should work without having to use this option).
By default SimpleBar automatically hides the scrollbar if the user is not scrolling (it emulates Mac OSX Lion's scrollbar). You can make the scrollbar always visible by setting the autoHide
option to false
:
new SimpleBar(document.getElementById('myElement'), { autoHide: false });
Default value is true
You can also control the animation via CSS as it's a simple CSS opacity transition.
Define the minimum scrollbar size in pixels.
Default value is 10
It is possible to specify css classes to change the design of the scrollbar. To get your own styles to work refer to simplebar.css
to get an idea how to setup your css.
content
represents the wrapper for the content being scrolled.scrollContent
represents the container containing elements being scrolled.scrollbar
defines the style of the scrollbar with which the user can interact to scroll the content.track
styles the area surrounding the scrollbar
.classNames: {
// defaults
content: 'simplebar-content',
scrollContent: 'simplebar-scroll-content',
scrollbar: 'simplebar-scrollbar',
track: 'simplebar-track'
}
If you later dynamically modify your content, for instance changing its height or width, or adding or removing content, you should recalculate the scrollbars like so:
var el = new SimpleBar(document.getElementById('myElement'));
el.SimpleBar.recalculate()
If you want to access to original scroll element, you can retrieve it via a getter :
var el = new SimpleBar(document.getElementById('myElement'));
el.SimpleBar.getScrollElement()
scroll
eventYou can subscribe to the scroll
event just like you do with native scrolling element :
var el = new SimpleBar(document.getElementById('myElement'));
el.SimpleBar.getScrollElement().addEventListener('scroll', function(...));
You can retrieve the element containing datas like this :
var el = new SimpleBar(document.getElementById('myElement'));
el.SimpleBar.getContentElement();
SimpleBar.removeObserver();
SimpleBar hides the browser's default scrollbars, which obviously is undesirable if the user has JavaScript disabled. To restore the browser's scrollbars you can include the following noscript
element in your document's head
:
<noscript>
<style>
[data-simplebar] {
overflow: auto;
}
</style>
</noscript>
Simplebar has been tested on the following browsers: Chrome, Firefox, Safari, Edge, IE11.
Notice: IE10 doesn't support MutationObserver
so you will still need to instantiate SimpleBar manually and call recalculate()
as needed (or you can just use a polyfill for MutationObserver
).
If you want to support IE9 you will need polyfills for:
classList
Or you can use SimpleBar v1.
http://grsmto.github.io/simplebar/
SimpleBar does only one thing : replace the browser's default scrollbars with a custom CSS-styled scrollbar without losing performance. Unlike most of others plugins, SimpleBar doesn't mimic scroll with Javascript, causing janks and strange scrolling behaviours...You keep the awesomeness of native scrolling...with a custom scrollbar! Design your scrollbar like you want, with CSS, on all browsers.
For the most part SimpleBar uses the browser's native scrolling functionality, but replaces the conventional scrollbar with a custom CSS-styled scrollbar. The plugin listens for scroll events and redraws the custom scrollbar accordingly.
Key to this technique is hiding the native browser scrollbar. The scrollable element is made slightly wider/taller than its containing element, effectively hiding the scrollbar from view.
See changelog here : https://github.com/Grsmto/simplebar/releases
Most of the credit goes to Jonathan Nicol who made the original plugin called Trackpad Scroll Emulator.
Website: http://html5up.net/
Yoh Suzuki: wrapContent option
FAQs
Scrollbars, simpler.
The npm package simplebar receives a total of 422,671 weekly downloads. As such, simplebar popularity was classified as popular.
We found that simplebar demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.