Kebechet.Blazor.Swiper
14.0.6
Prefix Reserved
See the version list below for details.
dotnet add package Kebechet.Blazor.Swiper --version 14.0.6
NuGet\Install-Package Kebechet.Blazor.Swiper -Version 14.0.6
<PackageReference Include="Kebechet.Blazor.Swiper" Version="14.0.6" />
<PackageVersion Include="Kebechet.Blazor.Swiper" Version="14.0.6" />
<PackageReference Include="Kebechet.Blazor.Swiper" />
paket add Kebechet.Blazor.Swiper --version 14.0.6
#r "nuget: Kebechet.Blazor.Swiper, 14.0.6"
#:package Kebechet.Blazor.Swiper@14.0.6
#addin nuget:?package=Kebechet.Blazor.Swiper&version=14.0.6
#tool nuget:?package=Kebechet.Blazor.Swiper&version=14.0.6
Blazor.Swiper
A Blazor wrapper for Swiper, built on the framework-agnostic Swiper Element web component. The Swiper bundle is shipped inside the package and auto-registered on startup - no npm build step and no manual <script> tags.
Live storybook - interactive stories for every option.
Installation
dotnet add package Kebechet.Blazor.Swiper
Usage
@using Kebechet.Blazor.Swiper
<Swiper Options="new() { Pagination = true, AllowSlidePrev = true }">
<SwiperSlide>Slide 1</SwiperSlide>
<SwiperSlide>Slide 2</SwiperSlide>
<SwiperSlide>Slide 3</SwiperSlide>
</Swiper>
Styling the shadow-DOM controls (pagination, arrows) is done via Swiper's CSS parts / variables - see the demo.
Any attribute you put on <Swiper> or <SwiperSlide> that isn't a parameter is forwarded to the underlying <swiper-container> / <swiper-slide> element, so class, style and id work as usual.
Options
SwiperOptions is a strongly-typed subset of Swiper's parameters. Nullable members that are left unset keep Swiper's own default.
| Option | Type | Default | Description |
|---|---|---|---|
Direction |
string |
horizontal |
Slider axis - use the SwiperDirection constants. |
SlidesPerView |
double? |
1 |
Number of slides visible at once. |
SpaceBetween |
int? |
0 |
Gap between slides, in px. |
Loop |
bool |
false |
Continuous loop mode. |
CenteredSlides |
bool |
false |
Center the active slide. |
AutoHeight |
bool |
false |
Track height follows the active slide's content height. |
InitialSlide |
int? |
0 |
Slide shown first. |
Speed |
int? |
300 |
Transition duration, in ms. |
AllowSlideNext |
bool |
true |
Allow moving to the next slide. |
AllowSlidePrev |
bool |
true |
Allow moving to the previous slide. |
AllowTouchMove |
bool |
true |
Allow touch/drag swiping at all. |
Pagination |
bool |
false |
Show the built-in pagination bullets. |
Navigation |
bool |
false |
Show the built-in prev/next arrows. |
Scrollbar |
bool |
false |
Show the built-in scrollbar. |
Keyboard |
bool |
false |
Enable keyboard control. |
Mousewheel |
bool |
false |
Enable mousewheel control. |
Observer |
bool |
false |
Swiper's MutationObserver, which auto-calls update() on any DOM change in the container. See below. |
CssMode |
bool |
false |
Use the browser's native CSS Scroll Snap API instead of JS transforms. See below. |
Observer is off by default
Swiper Element turns its MutationObserver on by default; this wrapper turns it off. With a framework re-rendering slide content - and especially with AutoHeight, whose height writes are themselves DOM mutations - it drives a costly update/height feedback loop. Call Update() explicitly instead when the slide collection changes, or set Observer = true if you want Swiper's behaviour back.
CssMode trades features for smoothness
CssMode = true moves the slider onto the browser's native CSS Scroll Snap API, so scrolling runs on the compositor thread - dramatically smoother for heavy or tall slides. In exchange (these are Swiper's own limitations, not the wrapper's):
- mouse-drag does not work - wheel, trackpad and touch still do, exactly like a native scroller
Speedis ignored- transition start/end events do not fire, so use
OnSlideChangerather thanOnTransitionEnd - it is not compatible with
Loop
Events
| Parameter | Type | Raised when |
|---|---|---|
OnSlideChange |
EventCallback<int> |
The slide changes; the argument is the new active index. |
OnReachBeginning |
EventCallback |
The first slide is reached. |
OnReachEnd |
EventCallback |
The last slide is reached. |
OnReady |
EventCallback |
Swiper has initialized and positioned its initial slide. |
OnTransitionEnd |
EventCallback |
A transition finishes, i.e. the slider has settled at rest. |
<Swiper Options="new() { Pagination = true }"
OnSlideChange="index => _current = index"
OnReachEnd="() => _atEnd = true">
<SwiperSlide>Slide 1</SwiperSlide>
<SwiperSlide>Slide 2</SwiperSlide>
</Swiper>
Programmatic control
Capture the component with @ref and drive it from C#. ActiveIndex is kept in sync with the underlying Swiper.
| Member | Description |
|---|---|
ActiveIndex |
The active slide index (read-only). |
SlideTo(int index, int? speed = null) |
Transition to the slide at index. |
SlideNext(int? speed = null) |
Transition to the next slide. |
SlidePrev(int? speed = null) |
Transition to the previous slide. |
Update() |
Recalculate Swiper after slides were added or removed. |
SetAllowSlideNext(bool value) |
Enable/disable moving forward at runtime. |
SetAllowSlidePrev(bool value) |
Enable/disable moving backward at runtime. |
<Swiper @ref="_swiper" Options="new() { AllowTouchMove = false }">
<SwiperSlide>Slide 1</SwiperSlide>
<SwiperSlide>Slide 2</SwiperSlide>
</Swiper>
<button @onclick="() => _swiper!.SlideNext()">Next</button>
@code {
private Swiper? _swiper;
}
Every method is a no-op until the component has rendered and its JS module has loaded, so calling one before OnReady does nothing.
Vertical direction needs a height
A vertical Swiper (Direction = SwiperDirection.Vertical) sizes its slides from the <Swiper> element's own height, which defaults to its content height. Give the <Swiper> an explicit height, or it collapses and slides stack:
<Swiper Options="new() { Direction = SwiperDirection.Vertical }" style="height: 300px;">
...
</Swiper>
License
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Microsoft.AspNetCore.Components.Web (>= 10.0.0)
-
net6.0
- Microsoft.AspNetCore.Components.Web (>= 6.0.0)
-
net7.0
- Microsoft.AspNetCore.Components.Web (>= 7.0.0)
-
net8.0
- Microsoft.AspNetCore.Components.Web (>= 8.0.0)
-
net9.0
- Microsoft.AspNetCore.Components.Web (>= 9.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Initial release wrapping Swiper 14.0.6 via the Swiper Element web component.