“this” won't refer to the div in a JQuery listener

旧时模样 提交于 2019-12-01 23:01:16

When using waypoint, this refers to the waypoint object. The waypoint object's element is the current div. So you would want to use

$(".my-class").waypoint(function(e) {
 $(this.element).addClass("hello");
})

From the api docs, they have a snippet like this:

var waypoints = $('#options-only').waypoint({
  handler: function(direction) {
    notify(this.element.id + ' hit')
  }
})

so you might need to do $(this.element), or maybe this.element is already a jquery object? I don't know much about waypoint.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!