简体   繁体   English

waypoints.js从元素获取ID

[英]waypoints.js get id from element

I try to use waypoints.js to update the url on a one page website. 我尝试使用waypoints.js更新一页网站上的网址。 The waypoints event is firing correct but i cant get the id out of the section i scrolled to. waypoints事件触发正确,但是我无法从滚动到的部分中获取ID。 The variable is always undefined. 该变量始终是未定义的。

$('section').waypoint(function() {
    var hash = $(this).attr('id');

    window.location.hash = (hash);
    currentHash = hash;
});

I solved it. 我解决了 You should use the this of waypoints.js: 您应该使用这个waypoints.js:

$('section').waypoint(function() {
    var hash = this.element.id

    window.location.hash = (hash);
    currentHash = hash;
});

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

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