Skip to content

Commit cb871a0

Browse files
author
unknown
committed
1.4.0
1 parent 717f1d8 commit cb871a0

18 files changed

+401
-342
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ I hope you love it!
2222

2323
## Demo
2424

25-
It's on the [GitHub Pages](http://utatti.github.com/perfect-scrollbar/).
25+
It's on the [GitHub Pages](http://utatti.github.io/perfect-scrollbar/).
2626

2727
## Table of Contents
2828

css/perfect-scrollbar.css

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,12 @@
5151
opacity: 0.6;
5252
}
5353

54-
.ps__rail-x:hover,
55-
.ps__rail-y:hover,
56-
.ps__rail-x:focus,
57-
.ps__rail-y:focus {
54+
.ps .ps__rail-x:hover,
55+
.ps .ps__rail-y:hover,
56+
.ps .ps__rail-x:focus,
57+
.ps .ps__rail-y:focus,
58+
.ps .ps__rail-x.ps--clicking,
59+
.ps .ps__rail-y.ps--clicking {
5860
background-color: #eee;
5961
opacity: 0.9;
6062
}
@@ -87,13 +89,15 @@
8789
}
8890

8991
.ps__rail-x:hover > .ps__thumb-x,
90-
.ps__rail-x:focus > .ps__thumb-x {
92+
.ps__rail-x:focus > .ps__thumb-x,
93+
.ps__rail-x.ps--clicking .ps__thumb-x {
9194
background-color: #999;
9295
height: 11px;
9396
}
9497

9598
.ps__rail-y:hover > .ps__thumb-y,
96-
.ps__rail-y:focus > .ps__thumb-y {
99+
.ps__rail-y:focus > .ps__thumb-y,
100+
.ps__rail-y.ps--clicking .ps__thumb-y {
97101
background-color: #999;
98102
width: 11px;
99103
}

dist/perfect-scrollbar.common.js

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*!
2-
* perfect-scrollbar v1.3.0
3-
* (c) 2017 Hyunje Jun
2+
* perfect-scrollbar v1.4.0
3+
* (c) 2018 Hyunje Jun
44
* @license MIT
55
*/
66
'use strict';
@@ -30,6 +30,7 @@ var elMatches =
3030
typeof Element !== 'undefined' &&
3131
(Element.prototype.matches ||
3232
Element.prototype.webkitMatchesSelector ||
33+
Element.prototype.mozMatchesSelector ||
3334
Element.prototype.msMatchesSelector);
3435

3536
function matches(element, query) {
@@ -64,6 +65,7 @@ var cls = {
6465
},
6566
state: {
6667
focus: 'ps--focus',
68+
clicking: 'ps--clicking',
6769
active: function (x) { return ("ps--active-" + x); },
6870
scrolling: function (x) { return ("ps--scrolling-" + x); },
6971
},
@@ -318,6 +320,7 @@ var env = {
318320

319321
var updateGeometry = function(i) {
320322
var element = i.element;
323+
var roundedScrollTop = Math.floor(element.scrollTop);
321324

322325
i.containerWidth = element.clientWidth;
323326
i.containerHeight = element.clientHeight;
@@ -369,7 +372,7 @@ var updateGeometry = function(i) {
369372
toInt(i.railYHeight * i.containerHeight / i.contentHeight)
370373
);
371374
i.scrollbarYTop = toInt(
372-
element.scrollTop *
375+
roundedScrollTop *
373376
(i.railYHeight - i.scrollbarYHeight) /
374377
(i.contentHeight - i.containerHeight)
375378
);
@@ -416,6 +419,8 @@ function getThumbSize(i, thumbSize) {
416419

417420
function updateCss(element, i) {
418421
var xRailOffset = { width: i.railXWidth };
422+
var roundedScrollTop = Math.floor(element.scrollTop);
423+
419424
if (i.isRtl) {
420425
xRailOffset.left =
421426
i.negativeScrollAdjustment +
@@ -426,13 +431,13 @@ function updateCss(element, i) {
426431
xRailOffset.left = element.scrollLeft;
427432
}
428433
if (i.isScrollbarXUsingBottom) {
429-
xRailOffset.bottom = i.scrollbarXBottom - element.scrollTop;
434+
xRailOffset.bottom = i.scrollbarXBottom - roundedScrollTop;
430435
} else {
431-
xRailOffset.top = i.scrollbarXTop + element.scrollTop;
436+
xRailOffset.top = i.scrollbarXTop + roundedScrollTop;
432437
}
433438
set(i.scrollbarXRail, xRailOffset);
434439

435-
var yRailOffset = { top: element.scrollTop, height: i.railYHeight };
440+
var yRailOffset = { top: roundedScrollTop, height: i.railYHeight };
436441
if (i.isScrollbarYUsingRight) {
437442
if (i.isRtl) {
438443
yRailOffset.right =
@@ -507,7 +512,8 @@ var dragThumb = function(i) {
507512
'scrollbarX',
508513
'scrollbarXWidth',
509514
'scrollLeft',
510-
'x' ]);
515+
'x',
516+
'scrollbarXRail' ]);
511517
bindMouseScrollHandler(i, [
512518
'containerHeight',
513519
'contentHeight',
@@ -516,7 +522,8 @@ var dragThumb = function(i) {
516522
'scrollbarY',
517523
'scrollbarYHeight',
518524
'scrollTop',
519-
'y' ]);
525+
'y',
526+
'scrollbarYRail' ]);
520527
};
521528

522529
function bindMouseScrollHandler(
@@ -531,6 +538,7 @@ function bindMouseScrollHandler(
531538
var scrollbarYHeight = ref[5];
532539
var scrollTop = ref[6];
533540
var y = ref[7];
541+
var scrollbarYRail = ref[8];
534542

535543
var element = i.element;
536544

@@ -550,6 +558,7 @@ function bindMouseScrollHandler(
550558

551559
function mouseUpHandler() {
552560
removeScrollingClass(i, y);
561+
i[scrollbarYRail].classList.remove(cls.state.clicking);
553562
i.event.unbind(i.ownerDocument, 'mousemove', mouseMoveHandler);
554563
}
555564

@@ -563,6 +572,8 @@ function bindMouseScrollHandler(
563572
i.event.bind(i.ownerDocument, 'mousemove', mouseMoveHandler);
564573
i.event.once(i.ownerDocument, 'mouseup', mouseUpHandler);
565574

575+
i[scrollbarYRail].classList.add(cls.state.clicking);
576+
566577
e.stopPropagation();
567578
e.preventDefault();
568579
});
@@ -575,7 +586,7 @@ var keyboard = function(i) {
575586
var scrollbarFocused = function () { return matches(i.scrollbarX, ':focus') || matches(i.scrollbarY, ':focus'); };
576587

577588
function shouldPreventDefault(deltaX, deltaY) {
578-
var scrollTop = element.scrollTop;
589+
var scrollTop = Math.floor(element.scrollTop);
579590
if (deltaX === 0) {
580591
if (!i.scrollbarYActive) {
581592
return false;
@@ -716,12 +727,13 @@ var wheel = function(i) {
716727
var element = i.element;
717728

718729
function shouldPreventDefault(deltaX, deltaY) {
730+
var roundedScrollTop = Math.floor(element.scrollTop);
719731
var isTop = element.scrollTop === 0;
720732
var isBottom =
721-
element.scrollTop + element.offsetHeight === element.scrollHeight;
733+
roundedScrollTop + element.offsetHeight === element.scrollHeight;
722734
var isLeft = element.scrollLeft === 0;
723735
var isRight =
724-
element.scrollLeft + element.offsetWidth === element.offsetWidth;
736+
element.scrollLeft + element.offsetWidth === element.scrollWidth;
725737

726738
var hitsBound;
727739

@@ -797,7 +809,7 @@ var wheel = function(i) {
797809
return true;
798810
}
799811
}
800-
var maxScrollLeft = cursor.scrollLeft - cursor.clientWidth;
812+
var maxScrollLeft = cursor.scrollWidth - cursor.clientWidth;
801813
if (maxScrollLeft > 0) {
802814
if (
803815
!(cursor.scrollLeft === 0 && deltaX < 0) &&
@@ -873,7 +885,7 @@ var touch = function(i) {
873885
var element = i.element;
874886

875887
function shouldPrevent(deltaX, deltaY) {
876-
var scrollTop = element.scrollTop;
888+
var scrollTop = Math.floor(element.scrollTop);
877889
var scrollLeft = element.scrollLeft;
878890
var magnitudeX = Math.abs(deltaX);
879891
var magnitudeY = Math.abs(deltaY);
@@ -1087,7 +1099,7 @@ var defaultSettings = function () { return ({
10871099
suppressScrollY: false,
10881100
swipeEasing: true,
10891101
useBothWheelAxes: false,
1090-
wheelPropagation: false,
1102+
wheelPropagation: true,
10911103
wheelSpeed: 1,
10921104
}); };
10931105

@@ -1218,7 +1230,7 @@ var PerfectScrollbar = function PerfectScrollbar(element, userSettings) {
12181230

12191231
this.settings.handlers.forEach(function (handlerName) { return handlers[handlerName](this$1); });
12201232

1221-
this.lastScrollTop = element.scrollTop; // for onScroll only
1233+
this.lastScrollTop = Math.floor(element.scrollTop); // for onScroll only
12221234
this.lastScrollLeft = element.scrollLeft; // for onScroll only
12231235
this.event.bind(this.element, 'scroll', function (e) { return this$1.onScroll(e); });
12241236
updateGeometry(this);
@@ -1270,7 +1282,7 @@ PerfectScrollbar.prototype.onScroll = function onScroll (e) {
12701282
this.element.scrollLeft - this.lastScrollLeft
12711283
);
12721284

1273-
this.lastScrollTop = this.element.scrollTop;
1285+
this.lastScrollTop = Math.floor(this.element.scrollTop);
12741286
this.lastScrollLeft = this.element.scrollLeft;
12751287
};
12761288

0 commit comments

Comments
 (0)