javascript - Waypoints 中的 jQuery 每个循环

标签 javascript jquery html css jquery-waypoints

我无法让 $.each() 在 Waypoints 中工作。我看过其他一些使用相同方法的 stackoverflow 帖子。所以我可能会遗漏一些东西。请帮忙!

我在 JSFiddle 上有它:https://jsfiddle.net/rs80dmn5/5/

这是 html:

<ul class="col-sm-6">
                <li>
                    <h2>10<span>year</span></h2>
                    <h2>100,000<span>miles</span></h2>
                    <p>Powertrain<br/>Warranty</p>
                </li>
                <li>
                    <h2>5<span>year</span></h2>
                    <h2>60,000<span>miles</span></h2>
                    <p>Limited Warranty</p>
                </li>
                <li>
                    <h2>5<span>year/unlimited miles</span></h2>
                    <h2>24<span>hour</span></h2>
                    <p>Roadside Assistance</p>
                </li>
                <li>
                    <p>You have certain expectations when looking for a new car and one of the most important is that it will last, which is why we back every Hyundai with “America’s Best Warranty.” It’s our way of showing how much confidence we have in the quality of the vehicles we make so you’ll have the confidence of knowing that the joy of ownership is one that will last for today, tomorrow and years down the road.</p>
                    <a href="#">Learn more about our Warranty</a>
                    <p><small>*America’s Best Warranty claim based on total package of warranty programs. See dealer for LIMITED WARRANTY details.</small></p>
                </li>
            </ul>

这是我的 CSS:

    ul,li {
  margin: 0;
  padding: 0;
  list-style: none;
}

li {
  height: 500px;
  width: 100%;
  display: block;
}

li h2 {
  font-size: 110px;
}

@keyframes fadeIn {
    0% {
        opacity: 0;
        margin-top: 20px;
    }
    100% {
        opacity: 1;
        margin-top: 0px;
    }
}

h2.fadeup {
    animation-name: fadeIn;
    animation-duration: 1s;
    animation-timing-function: linear;
    animation-delay: 0s;
    animation-iteration-count: 1;
    animation-fill-mode: forwards;
    animation-direction: normal;
}
li h2 span {
  font-size: 20px;
}

这是我的 JS:

$(document).ready(function(){

    $('h2').each( function(){

        $(this).waypoint({

            handler: function(){

                $(this).addClass('fadeup');

            }

        });

    });

});

我没有收到任何错误。然而什么也没有发生。

最佳答案

$(this)里面的$(this).waypoints({..指的是waypoint对象而不是元素h2

试试这个:

$('h2').each(function(){

    var self = $(this);

    $(this).waypoint({
         handler: function(){
             self.addClass('fadeup');
         }
    });
})

关于javascript - Waypoints 中的 jQuery 每个循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38753735/

相关文章:

html - 这个 fiddle 中额外的 5px 从哪里来?

javascript - 最初设置后无法删除更改内联 CSS 或从我的 div 中删除整个样式属性

javascript - 如果用户已登录,如何限制后退按钮,或直接在angularjs中访问登录页面

Javascript(jQuery)在拖动项目时禁用页面滚动

javascript - 将一次性事件附加到动态添加的元素

jquery - 在 jquery 中将子位置调整到父的中心

html - Bootstrap - 使用轮播作为固定背景

javascript - Node js - 如何访问同一 Controller 中的另一个函数

javascript - Silktide cookie 同意 3.0.3 与使用 CSS 伪元素的 Font Awesome 5.0.2 冲突

javascript - 在JS中访问导入模块中的私有(private)函数?