Swaps
Swaps define how new content replaces or is inserted into existing DOM elements. WSX provides flexible swap strategies with timing and animation controls.Basic Swap Types
innerHTML (Default)
Replace the content inside an element:outerHTML
Replace the entire element:Text Content
Replace only the text content:Positional Swaps
beforebegin
Insert before the element:afterbegin
Insert at the beginning of the element:beforeend
Insert at the end of the element:afterend
Insert after the element:Swap Specifications
Client-Side Specification
Usewx-swap
attribute to specify swap behavior:
Server-Side Specification
Specify swap in the response:Timing Modifiers
Swap Timing
Control when the swap occurs:Settle Timing
Control when animations settle:Server-Side Timing
Animation and Effects
Fade Effects
Slide Effects
Custom Animations
Scroll Behavior
Auto-Scroll
Control scrolling after swaps:Server-Side Scroll Control
Best Practices
- Choose Appropriate Swap Types: Use the right swap for your use case
- Add Smooth Transitions: Use timing modifiers for better UX
- Handle Scroll Behavior: Control scrolling for long content
- Clean Up Resources: Handle cleanup before swaps
- Test Animations: Ensure animations work across browsers
- Consider Performance: Avoid expensive animations on slow devices
Next Steps
- Learn about Out-of-Band Updates for multiple element updates
- Explore Client Events for swap event handling
- Understand Server Broadcasting for coordinated updates