Created
August 7, 2021 20:33
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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