El affix

From jiaiyan/element-plus-skills · View interactive version

El affix is an AI agent skill from the GitHub repository jiaiyan/element-plus-skills. Affix component for fixing elements to a specific visible area. Invoke when user needs to create sticky navigation, fixed headers, or elements that remain visible while scrolling.

How to use this skill

Skill file

Affix Component

Affix component fixes an element to a specific visible area, useful for sticky navigation, headers, or toolbars.

When to Use

Basic Usage

<template>
  <el-affix :offset="120">
    <el-button type="primary">Offset top 120px</el-button>
  </el-affix>
</template>

Target Container

<template>
  <div class="scroll-container" style="height: 400px; overflow: auto;">
    <el-affix target=".scroll-container" :offset="80">
      <el-button type="primary">Fixed in container</el-button>
    </el-affix>
  </div>
</template>

Fixed Position

<template>
  <el-affix position="top" :offset="20">
    <el-button type="primary">Fixed at top</el-button>
  </el-affix>
  
  <el-affix position="bottom" :offset="20">
    <el-button type="primary">Fixed at bottom</el-button>
  </el-affix>
</template>

API Reference

Attributes

| Name | Description | Type | Default |

|------|-------------|------|---------|

| offset | Offset distance | number | 0 |

| position | Position of affix | 'top' \| 'bottom' | 'top' |

| target | Target container (CSS selector) | string | — |

| z-index | z-index of affix | number | 100 |

| teleported | Whether affix element is teleported | boolean | false |

| append-to | Which element the affix appends to | CSSSelector \| HTMLElement | 'body' |

Events

| Name | Description | Type |

|------|-------------|------|

| change | Triggers when fixed state changed | (fixed: boolean) => void |

| scroll | Triggers when scrolling | ({ scrollTop: number, fixed: boolean }) => void |

Slots

| Name | Description |

|------|-------------|

| default | Customize default content |

Exposes

| Name | Description | Type |

|------|-------------|------|

| update | Update affix state manually | () => void |

| updateRoot | Update rootRect info | () => void |

Common Patterns

Sticky Header with State Tracking

<template>
  <el-affix :offset="0" @change="handleAffixChange">
    <header :class="{ 'is-fixed': isFixed }">
      <nav>Sticky Navigation</nav>
    </header>
  </el-affix>
</template>

<script setup>
import { ref } from 'vue'

const isFixed = ref(false)

const handleAffixChange = (fixed) => {
  isFixed.value = fixed
}
</script>

Best Practices

  1. Use target to limit affix to a specific container
  2. Set appropriate z-index to avoid layering issues
  3. Handle change event for UI state updates
Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.