Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ExileofAranei/d9a95922fb7fb2afd32504173c24022a to your computer and use it in GitHub Desktop.
Save ExileofAranei/d9a95922fb7fb2afd32504173c24022a to your computer and use it in GitHub Desktop.
Prepare swiper slides width with bootstrap grid to prevent layout jump on page load
@use "sass:map";
@mixin preset-slides-width($configuration: (), $gutter: $grid-gutter-width) {
@if type-of($gutter) == 'string' {
@error 'The second parameter of mixin must be a number. String is provided.';
}
width: 100%;
margin-right: $gutter;
@each $breakpoint, $count in $configuration {
$mediaValue: $breakpoint;
@if type-of($breakpoint) == 'string' {
$mediaValue: map.get($grid-breakpoints, $breakpoint);
@if ($mediaValue == null) {
@error ('Breakpoint with name "' + #{$breakpoint} + '" was not found at grid breakpoints list');
}
}
@media screen and (min-width: $mediaValue) {
width: calc((100% - #{$gutter * ($count - 1)}) / #{$count});
}
}
}
// Example usage
.my-swiper-slider {
.swiper-slide {
@include preset-slides-width(('sm': 2, 'md': 3, 'xl': 4), 32px);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment