Skip to content

Adds option to configure the friction for swipeEasing #142

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
<p align="center">Minimalistic but perfect custom scrollbar plugin<p>


<p align="center">
<p align="center">
<a href="https://npmcharts.com/compare/perfect-scrollbar?minimal=true"><img src="https://img.shields.io/npm/dm/perfect-scrollbar.svg" alt="Downloads"></a>
<a href="https://github.com/mdbootstrap/bootstrap-material-design/blob/master/License.pdf"><img src="https://img.shields.io/badge/license-MIT-green.svg" alt="License"></a>
<a href="https://badge.fury.io/js/perfect-scrollbar"><img src="https://badge.fury.io/js/perfect-scrollbar.svg" alt="npm"></a>
<a href="https://github.com/mdbootstrap/bootstrap-material-design/blob/master/License.pdf"><img src="https://img.shields.io/badge/license-MIT-green.svg" alt="License"></a>
<a href="https://badge.fury.io/js/perfect-scrollbar"><img src="https://badge.fury.io/js/perfect-scrollbar.svg" alt="npm"></a>
<a href="https://twitter.com/intent/tweet/?text=Thanks+@mdbootstrap+for+maintaining+amazing+and+free+Perfect+Scrollbar+Plugin%20https://perfectscrollbar.com/&hashtags=javascript,code,webdesign,bootstrap"><img src="https://img.shields.io/twitter/url/http/shields.io.svg?style=social&label=Let%20us%20know%20you%20were%20here%21&"></a>
<a href="https://www.youtube.com/watch?v=c9B4TPnak1A"><img alt="YouTube Video Views" src="https://img.shields.io/youtube/views/c9B4TPnak1A?label=Bootstrap%205%20Tutorial%20Views&style=social"></a>
</p>
Expand Down Expand Up @@ -55,14 +55,14 @@ Check out the [Live Preview](https://mdbootstrap.com/snippets/standard/marveluck

- [Twitter](https://twitter.com/MDBootstrap)

- [Facebook](https://www.facebook.com/mdbootstrap)
- [Facebook](https://www.facebook.com/mdbootstrap)

- [Pinterest](https://pl.pinterest.com/mdbootstrap)

- [Dribbble](https://dribbble.com/mdbootstrap)

- [LinkedIn](https://www.linkedin.com/company/material-design-for-bootstrap)

- [YouTube](https://www.youtube.com/channel/UC5CF7mLQZhvx8O5GODZAhdA)

## Get Free Material Design for Bootstrap 5
Expand All @@ -77,7 +77,7 @@ Check out the [Live Preview](https://mdbootstrap.com/snippets/standard/marveluck
</td>
<td>
<ul style="list-style-type:none;">
<li>Material Design 2.0 + latest Bootstrap 5 based on plain JavaScript. 700+ material UI components, super simple, 1 minute installation, free templates & much more</li>
<li>Material Design 2.0 + latest Bootstrap 5 based on plain JavaScript. 700+ material UI components, super simple, 1 minute installation, free templates & much more</li>
</ul>
</td>
</tr>
Expand Down
48 changes: 48 additions & 0 deletions examples/options-swipeEasingFriction.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<!DOCTYPE html>
<html>
<head>
<link href="../css/perfect-scrollbar.css" rel="stylesheet">
<script src="../dist/perfect-scrollbar.js"></script>
<style>
.container {
position: relative;
margin: 30px auto;
padding: 0px;
width: 600px;
height: 400px;
overflow: auto;
}
.container .content {
background-image: url('./assets/azusa.jpg');
width: 1280px;
height: 720px;
color: blue;
font-size: 20px;
}
</style>
</head>
<body>
<div class="container">
<div class="content">
swipeEasingFriction: 0.2
</div>
</div>
<div class="container">
<div class="content">
swipeEasingFriction: 0.05
</div>
</div>

<script>
var containers = document.querySelectorAll('.container');

new PerfectScrollbar(containers[0], {
swipeEasingFriction: 0.2
});

new PerfectScrollbar(containers[1], {
swipeEasingFriction: 0.05
});
</script>
</body>
</html>
4 changes: 2 additions & 2 deletions src/handlers/touch.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ export default function(i) {

applyTouchMove(speed.x * 30, speed.y * 30);

speed.x *= 0.8;
speed.y *= 0.8;
speed.x *= 1 - i.settings.swipeEasingFriction;
speed.y *= 1 - i.settings.swipeEasingFriction;
}, 10);
}
}
Expand Down
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const defaultSettings = () => ({
suppressScrollX: false,
suppressScrollY: false,
swipeEasing: true,
swipeEasingFriction: 0.2,
useBothWheelAxes: false,
wheelPropagation: true,
wheelSpeed: 1,
Expand Down
1 change: 1 addition & 0 deletions types/perfect-scrollbar.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ declare namespace PerfectScrollbar {
suppressScrollX?: boolean;
suppressScrollY?: boolean;
swipeEasing?: boolean;
swipeEasingFriction?: number;
useBothWheelAxes?: boolean;
wheelPropagation?: boolean;
wheelSpeed?: number;
Expand Down