当元素滚动到视图中时,jQuery Waypoints添加类 [英] jQuery Waypoints add class when element is scrolled into view

查看:106
本文介绍了当元素滚动到视图中时,jQuery Waypoints添加类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Waypoints 插件来检查元素是否滚动到视图中。当用户向下滚动页面时,我有多个具有类 item 的div,我想为每个添加一个查看类。

I'm using the Waypoints plugin to check if an element is scrolled into view. I have multiple divs with class item as the user scrolls down the page, I want to add a class "viewed" to each.

$(".item").waypoint(function(){
    $(this).addClass("viewed");
    console.log("yey");
});

console.log有效,但 .addClass 没有。该插件不支持 $(this)

The console.log works, but the .addClass doesn't. Does the plugin not support $(this)?

推荐答案

我终于让它运转。

$(".item").waypoint(function(){
   $(this[0,'element']).addClass("viewed");
});

未指向元素,所以我需要定位它。

The this wasn't pointed at the element, so I needed to target it.

这篇关于当元素滚动到视图中时,jQuery Waypoints添加类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆