-
-
Notifications
You must be signed in to change notification settings - Fork 214
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
Before and after offset? #25
Comments
Hey @exdeniz I think to achieve this behavior, it would be easier to use the slider with these options: new KeenSlider("#slider", {
slidesPerView: 2,
centered: true,
}) Do you agree? |
Hello @exdeniz okay, I get it now. I'll put it on my list, but I can't tell you when I'm gonna do it. There are some more important features for me right now that need some time. But I hope to give you this feature soon. |
Thank you, I understand that there are more important things, such as |
I think I saw this project on reddit. https://github.com/joe223/tiny-swiper Maybe, you should give it a try, if you look for a swiperjs-like lib. |
What about adding an extra empty div as last slide? It might be a quick solution |
|
I achieved your desired behavior with simple CSS: Give the https://codesandbox.io/s/new-frost-xkkm7?fontsize=14&hidenavigation=1&theme=dark |
In the new version of keen-slider you can configure the sizes, origins and spacing of each slide separately. So, I think this issue can be closed. |
Not want to reopen this issue but in the new keen-slider the origin parameter is just a percentage on the viewport. |
@liqueflies I had the same thing. You can specify |
Hey @liqueflies would it be helpful when the origin parameter can be a function? |
@rcbyr if the |
@rcbyr If origin could be a function and container size is provided, one could transform the px value into the value related to the container size. Anyways, unfortunately this does not help to achieve inline padding, as the last item would scroll to padding left. Happy to dig in and create a pull request. Following @setianke's approach does not work for some cases where |
Here's a snippet me and my colleague cook today: const createSlideConfigWithOffset =
({ perPage = 3, sideOffset = 20, spacing = 8, loop = false } = {}) =>
(sliderSize: number, slides: HTMLElement[]): TrackSlidesConfigOption =>
slides.map((_, slideIndex) => {
const size = (sliderSize - (sideOffset * 2 + spacing * (perPage - 1))) / perPage
let origin = sideOffset
if (!loop && slideIndex > slides.length - perPage) {
origin += (size + spacing) * (perPage - (slides.length - slideIndex))
}
return {
size: size / sliderSize,
spacing: spacing / sliderSize,
origin: origin / sliderSize,
}
}) Usage:const [ref] = useKeenSlider<HTMLDivElement>({
slides: createSlideConfigWithOffset({ perPage: 5, sideOffset: 20, spacing: 10 }),
}) With Looping: const [ref] = useKeenSlider<HTMLDivElement>({
loop: true,
slides: createSlideConfigWithOffset({ loop: true }),
}) |
Please add before and after offset like slidesOffsetBefore and slidesOffsetAfter like swiper.js. It's necessary when the slider is used full width screen and the slides go over the screen. Like slider on this page - http://exdeniz.protechnolog.danke.agency/career/
The text was updated successfully, but these errors were encountered: