首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在滚动页面上使用jQuery动画

如何在滚动页面上使用jQuery动画
EN

Stack Overflow用户
提问于 2018-08-04 04:14:20
回答 1查看 111关注 0票数 2

我有这个标记

代码语言:javascript
复制
            <div class="box-1 box">
                    <img src="img/interaction design.gif">
                    <h2>Interaction Design</h2>
                    <p class="description">Form follows function. Solution marries aesthetics. <br>
                        We help you design beautiful intuitive experiences through the 
                        use of UX/UI principles.
                    </p>

                    <p class="explanation">
                        - Website Design <br>
                        - Mobile Apps <br>
                        - Visual Style Guide <br>
                        - IA &amp; Wireframing
                    </p>
            </div>

            <div class="box-2 box">
                    <img src="img/graphicdesign.png">
                    <h2>Graphic Design</h2>
                    <p class="description">People are more likely to trust something that looks
                        good. I mean, you're reading this far because of that same reason. Right? Right.
                    </p>

                    <p class="explanation">
                        - Digital Graphics <br>
                        - Print Design <br>
                        - Custom Illustrations
                    </p>
            </div>

            <div class="box-3 box">
                    <img src="img/webdev.png">
                    <h2>Web Development</h2>
                    <p class="description">In order to give you and your business the best online experience
                        we can help you with your website and take your experiences up a notch with more
                        "Ooo's" and "Aah's" using the best methods available.
                    </p>

                    <p class="explanation">
                        - Front and Backend <br>
                        - Online Marketing <br>
                        - Search Machine Optimization
                    </p>
            </div>

    </div>

当我向下滚动时,我想让'box-1‘和'box-2’等元素从底部淡入,为此我使用了Animate Css,我的JavaScript看起来像这样:

代码语言:javascript
复制
var animationName = 'fadeInUp';
var animationEnd = 'animationend oAnimationEnd mozAnimationEnd                       webkitAnimationEnd';

$(function() {
    if ( $(window).scrollTop() === $('container-2').offset() ) {
        $('.box-1').addClass(animationName);
    } else {
        $('.box-1').removeClass(animationName);
    }
})

我也尝试过$(window).height(),但是没有添加这个类,非常感谢您的帮助。

谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-08-04 12:24:26

您可以对scroll事件进行编码,并使用offset top元素检查滚动值:

代码语言:javascript
复制
  $(window).scroll(function (event) {
        var scroll = $(window).scrollTop();
       if (scroll == $('.container-2').offset().top ) {
        $('.box-1').addClass('animationName');
        }else {
            $('.box-1').removeClass('animationName');
        }
    });
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51679549

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档