
Research
/Security News
GlassWASM: WebAssembly Malware Found in Trojanized Open VSX Extensions
The trojanized extensions use TinyGo-compiled WebAssembly and Solana transaction memos to resolve command-and-control infrastructure.
vue-use-fixed-header
Advanced tools
Turn your boring fixed header into a smart one with three lines of code.
Turn your boring fixed header into a smart one with three lines of code.
Demo: Website — Examples: Vue 3 - Nuxt 3
pnpm add vue-use-fixed-header
yarn add vue-use-fixed-header
npm i vue-use-fixed-header
Pass your header's template ref to useFixedHeader. Then apply the returned reactive styles. That's it.
<script setup>
import { ref } from 'vue'
import { useFixedHeader } from 'vue-use-fixed-header'
const headerRef = ref(null)
const { styles } = useFixedHeader(headerRef)
</script>
<template>
<header class="Header" ref="headerRef" :style="styles">
<!-- Your content -->
</header>
</template>
<style scoped>
.Header {
position: fixed; /* or sticky */
top: 0;
/* Other styles... */
}
</style>
All you have to do is to set position: fixed (or sticky) to your header. useFixedHeader will take care of the rest.
On resize, useFixedHeader checks your header's position and display properties to determine whether its functionalities should be enabled or not.
Disabled means that no event listeners are attached and the returned styles match an empty object {}.
Hence feel free to have code like this, it will just work as expected:
.Header {
position: fixed;
}
/* Will be disabled */
@media (max-width: 768px) {
.Header {
position: relative;
}
}
/* Same */
@media (max-width: 375px) {
.Header {
display: none;
}
}
Let's suppose your header in some pages is not fixed/sticky and you're using some reactive logic to determine whether it should be or not.
You can pass a signal to the watch property of useFixedHeader to perform a check everytime the value changes:
<script setup>
const route = useRoute()
const headerRef = ref(null)
const isPricingPage = computed(() => route.name === 'Pricing')
const { styles } = useFixedHeader(headerRef, {
watch: isPricingPage, // Will perform a check everytime the value changes
})
</script>
<template>
<header
ref="headerRef"
:style="{
...styles,
position: isPricingPage ? 'relative' : 'fixed',
}"
>
<!-- Your content -->
</header>
</template>
useFixedHeader will automatically toggle functionalities when navigating to/from the Pricing page.
You can pass either a
refor acomputed(without.value).
declare function useFixedHeader(
target: Ref<HTMLElement | null> | HTMLElement | null
options?: UseFixedHeaderOptions
): {
styles: Readonly<ShallowRef<CSSProperties>>
isEnter: ComputedRef<boolean>
isLeave: ComputedRef<boolean>
}
interface UseFixedHeaderOptions {
/**
* Scrolling container. Matches `document.documentElement` if `null`.
*
* @default null
*/
root: Ref<HTMLElement | null> | HTMLElement | null
/**
* Signal without `.value` (ref or computed) to be watched
* for automatic behavior toggling.
*
* @default null
*/
watch: Ref<T> | ComputedRef<T>
/**
* Whether to transition `opacity` property from 0 to 1
* and vice versa along with the `transform` property
*
* @default false
*/
transitionOpacity: boolean | Ref<boolean> | ComputedRef<boolean>
}
MIT Licensed - Simone Mastromattei © 2023
FAQs
Turn your boring fixed header into a smart one with three lines of code.
The npm package vue-use-fixed-header receives a total of 166 weekly downloads. As such, vue-use-fixed-header popularity was classified as not popular.
We found that vue-use-fixed-header demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Research
/Security News
The trojanized extensions use TinyGo-compiled WebAssembly and Solana transaction memos to resolve command-and-control infrastructure.

Security News
Anthropic says the directive cited national security concerns over a narrow jailbreak, but offered no specific technical details.

Security News
A network of 152 Chrome live wallpaper extensions hid ad tracking and made extension-driven traffic look like Google search clicks.