Skip to content

Commit

Permalink
feat(scrollbar): add directional classes to scrollbar container
Browse files Browse the repository at this point in the history
  • Loading branch information
nolimits4web committed Jun 8, 2022
1 parent 097390d commit 083a83f
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
10 changes: 10 additions & 0 deletions src/modules/scrollbar/scrollbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export default function Scrollbar({ swiper, extendParams, on, emit }) {
lockClass: 'swiper-scrollbar-lock',
dragClass: 'swiper-scrollbar-drag',
scrollbarDisabledClass: 'swiper-scrollbar-disabled',
horizontalClass: `swiper-scrollbar-horizontal`,
verticalClass: `swiper-scrollbar-vertical`,
},
});

Expand Down Expand Up @@ -271,6 +273,8 @@ export default function Scrollbar({ swiper, extendParams, on, emit }) {
$el = $swiperEl.find(params.el);
}

$el.addClass(swiper.isHorizontal() ? params.horizontalClass : params.verticalClass);

let $dragEl = $el.find(`.${swiper.params.scrollbar.dragClass}`);
if ($dragEl.length === 0) {
$dragEl = $(`<div class="${swiper.params.scrollbar.dragClass}"></div>`);
Expand All @@ -293,6 +297,12 @@ export default function Scrollbar({ swiper, extendParams, on, emit }) {
}
}
function destroy() {
const params = swiper.params.scrollbar;
const $el = swiper.scrollbar.$el;
if ($el) {
$el.removeClass(swiper.isHorizontal() ? params.horizontalClass : params.verticalClass);
}

disableDraggable();
}

Expand Down
6 changes: 4 additions & 2 deletions src/modules/scrollbar/scrollbar.less
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@
&.swiper-scrollbar-disabled {
display: none !important;
}
.swiper-horizontal > & {
.swiper-horizontal > &,
&.swiper-scrollbar-horizontal {
position: absolute;
left: 1%;
bottom: 3px;
z-index: 50;
height: 5px;
width: 98%;
}
.swiper-vertical > & {
.swiper-vertical > &,
&.swiper-scrollbar-vertical {
position: absolute;
right: 3px;
top: 1%;
Expand Down
6 changes: 4 additions & 2 deletions src/modules/scrollbar/scrollbar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@
&.swiper-scrollbar-disabled {
display: none !important;
}
.swiper-horizontal > & {
.swiper-horizontal > &,
&.swiper-scrollbar-horizontal {
position: absolute;
left: 1%;
bottom: 3px;
z-index: 50;
height: 5px;
width: 98%;
}
.swiper-vertical > & {
.swiper-vertical > &,
&.swiper-scrollbar-vertical {
position: absolute;
right: 3px;
top: 1%;
Expand Down
14 changes: 14 additions & 0 deletions src/types/modules/scrollbar.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,18 @@ export interface ScrollbarOptions {
* @default 'swiper-scrollbar-disabled'
*/
scrollbarDisabledClass?: string;

/**
* CSS class name set to scrollbar in horizontal Swiper
*
* @default 'swiper-scrollbar-horizontal'
*/
horizontalClass?: string;

/**
* CSS class name set to scrollbar in vertical Swiper
*
* @default 'swiper-scrollbar-vertical'
*/
verticalClass?: string;
}

0 comments on commit 083a83f

Please sign in to comment.