<template>
<div class="aaa" style="height: 2000px;">
<div class="inputname" :style="{'background-color':backgroundColor,height:'50px',width:'100%'}">
</div>
</div>
</template>
<script setup lang="ts">
import {ref,reactive} from "vue"
const backgroundColor = ref("#95ec69")
const handleScroll= ()=> {
let scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;
let offsetTop = document.querySelector(".inputname").offsetTop;
let he1 = 1300 -scrollTop
backgroundColor.value = `rgba(149, 236, 105,${he1 / 1300})`;
}
window.addEventListener("scroll", handleScroll);
</script>
<style scoped>
.inputname {
position: sticky;
background: red;
top: 0;
font-size: 20px;
z-index: 1;
}
</style>