---
title: "onScrollTargetVisibilityChange(idType:threshold:_:)"
framework: swiftui
role: symbol
role_heading: Instance Method
path: "swiftui/view/onscrolltargetvisibilitychange(idtype:threshold:_:)"
---

# onScrollTargetVisibilityChange(idType:threshold:_:)

Adds an action to be called with information about what views would be considered visible.

## Declaration

```swift
nonisolated func onScrollTargetVisibilityChange<ID>(idType: ID.Type, threshold: Double = 0.5, _ action: @escaping ([ID]) -> Void) -> some View where ID : Hashable

```

## Parameters

- `idType`: The type of Identity provided by the subviews.
- `threshold`: The amount required to be visible within the viewport of the the scrollview before the action is fired. By default when the view has crossed more than 50% on-screen, the action will be called.
- `action`: The action which will be called when the views within the scroll view cross the provided threshold. The callback will include which views are considered visible.

## Discussion

Discussion Use this modifier along with the modifier View/scrollTargetLayout() to be informed when the views in the targetted scroll view have crossed the provided threshold to be considered on/off screen. ScrollView {     LazyVStack {         ForEach(models) { model in             CardView(model: model)         }     }     .scrollTargetLayout() } .onScrollTargetVisibilityChange(for: Model.ID.self, threshold: 0.2) { onScreenCards in     // Disable video playback for cards that are offscreen... }

## See Also

### Responding to scroll view changes

- [onScrollGeometryChange(for:of:action:)](swiftui/view/onscrollgeometrychange(for:of:action:).md)
- [onScrollVisibilityChange(threshold:_:)](swiftui/view/onscrollvisibilitychange(threshold:_:).md)
- [onScrollPhaseChange(_:)](swiftui/view/onscrollphasechange(_:).md)
- [ScrollGeometry](swiftui/scrollgeometry.md)
- [ScrollPhase](swiftui/scrollphase.md)
- [ScrollPhaseChangeContext](swiftui/scrollphasechangecontext.md)
