简体   繁体   English

<a>使用JavaScript</a>检测<a>区域内</a>

[英]Detect an <a> inside an area using JavaScript

My problem is, I got an horizontal slider with years inside so its like a timeline, the years are fetched by a query, at this moment, the user has to scroll by the years and then click one specific year and the information on the website will filter. 我的问题是,我有一个带有年份的水平滑块,所以它就像一个时间轴,通过查询获取年份,此刻,用户必须按年份滚动,然后单击一个特定年份,然后在网站上单击信息。将过滤。

Is there a way to detect the year that is in the center of that horizontal slide? 有没有办法检测水平幻灯片中心的年份? Maybe with a hidden area at the center? 也许在中央有一个隐藏区域?

maybe you should observe the scroll event of the slider element. 也许您应该观察一下滑块元素的滚动事件。 you have to measure after each scroll process which element is inside of the visible slider area (I suppose others are hidden by overflow: scroll from the CSS, right?)... 您必须在每次滚动过程之后测量可见滑块区域内的哪个元素(我想其他元素被overflow: scroll隐藏了overflow: scroll从CSS overflow: scroll ,对吗?)...

you should use a small delay so that the function only triggers when the scrolling was really stopped and not constantly 您应该使用一个小的延迟,以便该功能仅在滚动真正停止时才触发,而不是在持续滚动时才触发

as it is better to show that with actually working code... checkout my jsfiddle . 因为最好通过实际工作的代码来证明这一点...检出我的jsfiddle It is at least working in Chrome but I suppose it will work in other browsers too... when you scroll through the year list and you stop for 50ms this list item that is visible in the visible area of the slider div is logged into with console.log into the JS console... hope that helps you =) 它至少可以在Chrome浏览器中使用,但我想它也可以在其他浏览器中使用...当您滚动浏览年份列表并停止50ms时,该列表项在div的可见区域中可见,并使用console.log进入JS控制台...希望对您有帮助=)

EDIT: had a small CSS error... fixed and URL updated 编辑:有一个小的CSS错误...已修复,URL已更新

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

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