Skip to content
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

Add wheelPropagationDisabledIfScrollable option #145

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
21 changes: 17 additions & 4 deletions dist/perfect-scrollbar.common.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/perfect-scrollbar.common.js.map

Large diffs are not rendered by default.

21 changes: 17 additions & 4 deletions dist/perfect-scrollbar.esm.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/perfect-scrollbar.esm.js.map

Large diffs are not rendered by default.

21 changes: 17 additions & 4 deletions dist/perfect-scrollbar.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/perfect-scrollbar.js.map

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions dist/perfect-scrollbar.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/perfect-scrollbar.min.js.map

Large diffs are not rendered by default.

52 changes: 48 additions & 4 deletions examples/options-wheelPropagation.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@
font-size: 20px;
}

.container .content-no-scroll {
background-image: url('https://mdbootstrap.com/img/Marketing/general/logo/big/mdb.png');
width: 12800px;
height: 200px;
color: blue;
font-size: 20px;
}

.container .smaller-font-size {
font-size: 12px;
}

.space {
padding: 150px 0;
text-align: center;
Expand Down Expand Up @@ -94,18 +106,42 @@ <h1>Wheel Propagation</h1>

<br>
<div class="space my-5">FOR SPACE</div>
<div class="container">
<div class="content-no-scroll">
<div class="alert alert-primary sticky-top font-weight-bold m-5" role="alert" style="z-index: 10; width:300px">
Default (not scrollable)
</div>
</div>
</div>
<div class="space my-5">FOR SPACE</div>
<div class="container">
<div class="content">
<div class="alert alert-primary sticky-top font-weight-bold m-5" role="alert" style="z-index: 10; width:300px">
Default
Default (scrollable)
</div>
</div>
</div>
<div class="space my-5">FOR SPACE</div>
<div class="container">
<div class="content">
<div class="alert alert-primary sticky-top font-weight-bold m-5" role="alert" style="z-index: 10; width:300px">
wheelPropagation: true
wheelPropagation: false
</div>
</div>
</div>
<div class="space my-5">FOR SPACE</div>
<div class="container">
<div class="content-no-scroll">
<div class="alert alert-primary sticky-top font-weight-bold m-5 smaller-font-size" role="alert" style="z-index: 10; width:300px">
wheelPropagationDisabledIfScrollable: true<br>(not scrollable)
</div>
</div>
</div>
<div class="space my-5">FOR SPACE</div>
<div class="container">
<div class="content">
<div class="alert alert-primary sticky-top font-weight-bold m-5 smaller-font-size" role="alert" style="z-index: 10; width:300px">
wheelPropagationDisabledIfScrollable: true<br>(scrollable)
</div>
</div>
</div>
Expand All @@ -119,11 +155,19 @@ <h1>Wheel Propagation</h1>
var containers = document.querySelectorAll('.container');

new PerfectScrollbar(containers[0]);
new PerfectScrollbar(containers[1]);

new PerfectScrollbar(containers[1], {
wheelPropagation: true
new PerfectScrollbar(containers[2], {
wheelPropagation: false
});

new PerfectScrollbar(containers[3], {
wheelPropagationDisabledIfScrollable: true
});

new PerfectScrollbar(containers[4], {
wheelPropagationDisabledIfScrollable: true
});
</script>


Expand Down
6 changes: 5 additions & 1 deletion src/handlers/keyboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,16 @@ export default function(i) {
const scrollTop = Math.floor(element.scrollTop);
if (deltaX === 0) {
if (!i.scrollbarYActive) {
return false;
return !i.settings.wheelPropagationDisabledIfScrollable;
}
if (
(scrollTop === 0 && deltaY > 0) ||
(scrollTop >= i.contentHeight - i.containerHeight && deltaY < 0)
) {
if (i.settings.wheelPropagationDisabledIfScrollable) {
return true;
}

return !i.settings.wheelPropagation;
}
}
Expand Down
10 changes: 9 additions & 1 deletion src/handlers/mouse-wheel.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,15 @@ export default function(i) {
hitsBound = isLeft || isRight;
}

return hitsBound ? !i.settings.wheelPropagation : true;
if (hitsBound) {
if (i.settings.wheelPropagationDisabledIfScrollable) {
return element.scrollHeight > element.clientHeight;
}

return !i.settings.wheelPropagation;
}

return true;
}

function getDeltaFromEvent(e) {
Expand Down
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const defaultSettings = () => ({
swipeEasing: true,
useBothWheelAxes: false,
wheelPropagation: true,
wheelPropagationDisabledIfScrollable: false,
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 @@ -11,6 +11,7 @@ declare namespace PerfectScrollbar {
swipeEasing?: boolean;
useBothWheelAxes?: boolean;
wheelPropagation?: boolean;
wheelPropagationDisabledIfScrollable?: boolean;
wheelSpeed?: number;
}
}
Expand Down