【发布时间】:2015-09-21 17:07:10
【问题描述】:
我正在努力从我的 HTML 元素的数据属性中获取值。对于每个元素,我想使用不同的偏移量,所以我计划从数据属性中获取偏移量值。
这是我的代码
<div class="waypoint" data-waypoint-offset="50%" >
// my code
</div>
这是我的脚本
$('.waypoint').waypoint(function() {
$(this.element).addClass('animated');
}, {
triggerOnce: true,
offset: function() {
return $(this.element).data('waypoint-offset');
}
})
但只有在元素到达顶部(偏移量 0)后才添加“动画”类。
我也试过了
return $(this).data('waypoint-offset');
但没有帮助。
谢谢
【问题讨论】:
标签: jquery offset jquery-waypoints