Scroll this page, then enable scroll lock to prevent background scrolling. Add multiple locks to test reference counting.
Add Scroll Lock
Remove Last Lock
Clear All Locks
Current Lock Status
Locks Added (This Demo)
0
No scroll locks active. Background scrolling is enabled.
How It Works
- Reference Counting: Multiple overlays can lock scroll independently
- iOS Compatible: Uses position:fixed to prevent scroll-jank on mobile
- Position Preservation: Your scroll position is saved and restored
- Automatic Unlock: Scroll unlocks when all locks are removed
@inject IScrollLockService ScrollLockService
// Lock scrolling (increments internal reference count)
await ScrollLockService.LockAsync();
// Unlock scrolling (decrements internal reference count)
await ScrollLockService.UnlockAsync();
// Check lock status
bool isLocked = ScrollLockService.IsLocked; // True if any locks active
int lockCount = ScrollLockService.LockCount; // Current reference count
// Multiple overlays can lock independently:
await ScrollLockService.LockAsync(); // Lock count: 1, IsLocked: true
await ScrollLockService.LockAsync(); // Lock count: 2, IsLocked: true
await ScrollLockService.UnlockAsync(); // Lock count: 1, IsLocked: true
await ScrollLockService.UnlockAsync(); // Lock count: 0, IsLocked: false