英文:
how to check window scrollTop on svelte project?
问题
I'm working on a svelte project and I'm having issues getting the window scrollTop value when I scroll the website...
I tried running this code in the svelte page route:
<script>
function checkScroll() {
console.log("Scrolled");
}
</script>
<svelte:window on:scrollX={checkScroll}/>
When I run this on dev server console remains empty...
I can't figure out what I'm doing wrong or not doing...
英文:
I'm working on a svelte project and I'm having issues getting the window scrollTop value when I scroll the website...
I tried running this code in the svelte page route:
<script>
function checkScroll() {
console.log("Scrolled");
}
</script>
<svelte:window on:scrollX={checkScroll}/>
When I run this on dev server console remains empty..
I can't figure out what I'm doing wrong or not doing...
答案1
得分: 1
You could bind the value directly to a variable tutorial
<script>
let x //to the right
let y //down
</script>
<svelte:window bind:scrollX={x} bind:scrollY={y}/>
或者根据您的需求以这种方式监听事件
<script>
function handleScroll(event) {
console.log('scrolling')
}
</script>
<svelte:window on:scroll={handleScroll}/>
英文:
You could bind the value directly to a variable tutorial
<script>
let x //to the right
let y //down
</script>
<svelte:window bind:scrollX={x} bind:scrollY={y}/>
or listen to the event like this depending on your needs
<script>
function handleScroll(event) {
console.log('scrolling')
}
</script>
<svelte:window on:scroll={handleScroll}/>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论