【问题标题】:waypoints, offset value from the data attribute航点,数据属性的偏移值
【发布时间】: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


    【解决方案1】:

    这是插件作者的修复,

    $('.waypoint').each(function() {
        var $element = $(this);
    
        $element.waypoint(function() {
            $element.addClass('animated');
            this.destroy();
        }, {
            offset: $element.data('waypoint-offset')
        });
    });
    

    以上答案也可以在 github 线程中找到,https://github.com/imakewebthings/waypoints/issues/452 感谢imakewebthings

    【讨论】:

      猜你喜欢
      • 2015-03-07
      • 1970-01-01
      • 2021-08-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-28
      • 1970-01-01
      • 2022-09-28
      相关资源
      最近更新 更多