BlazorHorizontalScroller 1.0.8

There is a newer version of this package available.
See the version list below for details.
dotnet add package BlazorHorizontalScroller --version 1.0.8
                    
NuGet\Install-Package BlazorHorizontalScroller -Version 1.0.8
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="BlazorHorizontalScroller" Version="1.0.8" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="BlazorHorizontalScroller" Version="1.0.8" />
                    
Directory.Packages.props
<PackageReference Include="BlazorHorizontalScroller" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add BlazorHorizontalScroller --version 1.0.8
                    
#r "nuget: BlazorHorizontalScroller, 1.0.8"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package BlazorHorizontalScroller@1.0.8
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=BlazorHorizontalScroller&version=1.0.8
                    
Install as a Cake Addin
#tool nuget:?package=BlazorHorizontalScroller&version=1.0.8
                    
Install as a Cake Tool

πŸ“¦ BlazorHorizontalScroller

A lightweight horizontal scroller component for Blazor WebAssembly and Blazor Server apps. Supports inertia-based dragging, snapping, item spacing, overflow control, and carousel mode β€” with smooth, touch-friendly interactions powered by JavaScript interop.

It is meant to be a super lightweight version of Slick Carousel, so I didn't include fancy stuff, but you can code some yourself using the callbacks.

This nuget is subject to big changes, use with precaution.

Big thanks to ChatGPT for assisting in creating this component!


✨ Features

  • No external dependencies
  • Carousel mode with responsive slides-per-view control
  • Customizable overflow behavior
  • Optional inertia and decay-based drag scrolling
  • Snap-to-item enabled by default with configurable delay
  • Supports mouse, touch, and programmatic scrolling

πŸ“¦ Installation

Add the NuGet package to your project:

dotnet add package BlazorHorizontalScroller

Then, add this in the file you want to use

@using BlazorHorizontalScroller

πŸ”§ Usage

Basic Example

<HorizontalScroller Items="myItems">
        <ItemTemplate>
            <div>
                @context
            </div>
        </ItemTemplate>
</HorizontalScroller>

Sliding cards overflowing example

When using AllowOverflow=true, you should style some ancestor with overflow-x: hidden; to delimit the overflow. It will avoid the overflow going out of the page. But don't set it on the body tag, as this will prevent your whole page from using position: sticky;.

<HorizontalScroller Items="myItems"
                    ItemTemplate="item => @<div class='card' style='width: 70vw;max-width: 70vw;'>@item</div>"
                    ItemSpacing="2rem"
                    AllowOverflow="true" />
@using BlazorHorizontalScroller
<HorizontalScroller Items="myItems"
                    ItemTemplate="item => @<div class='card'>@item</div>"
                    CarouselMode="true"
                    CarouselItemsPerSlideSelector="info => info!.ViewportWidth > 800 ? 3 : 1" />

πŸ“ Parameters

Parameter Type Default Description
Items IEnumerable<TItem> Required Collection of items to render
ItemTemplate RenderFragment<TItem> Required Template for each item
ItemSpacing string "1rem" Spacing between items
AllowOverflow bool false Allow horizontal overflow
OverflowViewportWidth string "100%" Width of the viewport when overflow is enabled
OverflowAllowedWidthOnLeft string "10rem" Width of allowed overflow on the left
EndSpacerWidth string "300px" Space after the last item
EnableInertia bool true Enable inertia scrolling
InertiaDecay double 0.9 Decay rate of inertia
EnableDrag bool true Enable drag interactions
EnableSnapping bool true Snap to the nearest item after drag
SnapDelay int 100 Delay before snapping (ms)
CarouselMode bool false Enable carousel-like behavior
CarouselItemsPerSlideSelector Func<WidthInfo?, int> _ => 1 Number of items per slide based on viewport width
OnSnappedToIndex EventCallback<int> β€” Invoked when snapped to an item
SelectedIndex int 0 Sets the selected slide index
SelectedIndexChanged EventCallback<int> β€” Callback invoked when selected index changes

πŸ“± Methods

Method Description
SnapToNextAsync() Programmatically snap to the next item
SnapToPreviousAsync() Programmatically snap to the previous item
SnapToIndexAsync() Programmatically snap to the selected slide index (not item index)

πŸ“Š WidthInfo Struct

public record WidthInfo(double ParentWidth, double ViewportWidth);

Useful for responsive calculations in your CarouselItemsPerSlideSelector delegate.


πŸ“œ Notes

  • When AllowOverflow is true, you might need to apply overflow-x: hidden to a parent container to prevent unwanted page scrollbars.
  • The component relies on a JS module (horizontalScroller.min.js) for drag, inertia, and snapping behavior. Make sure it’s properly published in your _content/BlazorHorizontalScroller/ directory.

πŸ“£ License

MIT License β€” free to use, modify, and distribute.

Product Compatible and additional computed target framework versions.
.NET 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 was computed.  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 was computed.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.30 198 8/5/2025
1.0.29 192 8/5/2025
1.0.28 58 8/1/2025
1.0.27 50 8/1/2025
1.0.26 61 8/1/2025
1.0.25 60 8/1/2025
1.0.24 65 8/1/2025
1.0.23 111 7/31/2025
1.0.22 117 7/31/2025
1.0.21 113 7/30/2025
1.0.20 141 7/8/2025
1.0.19 133 7/8/2025
1.0.18 134 7/8/2025
1.0.17 145 6/18/2025
1.0.16 162 5/28/2025
1.0.15 145 5/27/2025
1.0.14 147 5/27/2025
1.0.13 147 5/27/2025
1.0.12 144 5/26/2025
1.0.11 144 5/26/2025
1.0.10 86 5/23/2025
1.0.9 93 5/23/2025
1.0.8 143 5/22/2025
1.0.7 160 5/21/2025
1.0.6 143 5/21/2025
1.0.5 147 5/21/2025
1.0.4 142 5/21/2025
1.0.1 145 5/20/2025
1.0.0 145 5/20/2025

First publish. Please do not use for now