简体   繁体   English

滚动时 JavaScript 数字会发生变化

[英]JavaScript Number changes while scrolling

I'm currently working on a website.我目前在一个网站上工作。 I want to have a fixed text (I know how to do that) that changes if you scroll.我想要一个固定的文本(我知道怎么做),如果你滚动它就会改变。

So if you're on top of the page it shows '0' and then, while scrolling, the number goes up and up and when you scrolled one viewport-height it should be '10000'.因此,如果您在页面顶部,它会显示“0”,然后在滚动时,数字会不断上升,当您滚动一个视口高度时,它应该是“10000”。

I think this should be done with javascript, but I'm just a beginner with it.我认为这应该用 javascript 来完成,但我只是一个初学者。 Could you please help me?请你帮助我好吗? Thank you very much.非常感谢。

edit编辑

Thanks Ajay for the tip with the onscroll function.感谢 Ajay 提供有关 onscroll 功能的提示。 But this always just adds a number on scrolling.但是始终只是增加了上滚动的数字。 I want something like this (look at the top left hand corner).我想是这样(看左上方右上角)。 Where the size is relative to the position on the site and not the scrolling wheel.其中大小是相对于站点上的位置而不是滚轮。

Try using the onScroll event of javascript.尝试使用 javascript 的 onScroll 事件。

Here is a useful link to learn.是一个有用的学习链接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM