使用.destroy();带有Waypoint,但仅在一个对象上 [英] Use .destroy(); with Waypoints but only on one object

查看:128
本文介绍了使用.destroy();带有Waypoint,但仅在一个对象上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个不同的对象用于触发两个不同的Waypoint事件,这些事件随后触发Velocity.js(淡入/淡出库).

I have two different objects I'm using to trigger two different Waypoints events which then trigger Velocity.js (a fade in/out library).

第一个偶数(在secondary上的那个)应该永恒地上下起火,并且每次都起火.但是,在.process上的第二个应该只触发一次,然后再重新触发,直到重新加载页面为止.

The first even (the one on secondary) should fire eternally, up and down and every time. The second however, on .process should only fire once and then never again until the page is reloaded.

当我在第二个函数中插入.destroy();时,它将关闭整个页面的所有航路点事件.知道为什么吗?

When I insert .destroy(); in the second function, it shuts off all waypoints events for the entire page. Any idea why?

参考页: http://www.goodcorps.com/

if (document.documentElement.clientWidth > 990) {

    $('.secondary').waypoint(function(direction) {
        $('.intro').toggleClass('hidden');
    }, { 
        offset: "0%",
    });

    $('.home .process').waypoint(function(direction) {
        $('.illus.crosses svg g').velocity("transition.fadeIn", { 
            stagger: 50,
            duration: 100,
        });
        $(this).destroy(); // here's my attempted location
    }, { 
        offset: "20%",
    });

     } else {

    $('.home .process').waypoint(function(direction) {
        $('.illus.crosses svg g').velocity("transition.fadeIn", { 
            stagger: 50,
            duration: 100,
        });
        $(this).destroy(); // here's my attempted location
    }, { 
        offset: "50%",
    });
}

推荐答案

您共享的页面似乎不包含您在代码示例中引用的销毁调用,但是如果包含了这些调用,您应该会看到未捕获的TypeError未定义不是函数".原因:您正在调用$(this).destroy()而不是this.destroy(). destroy是Waypoint实例上的函数.当您尝试在$()返回的jQuery对象上调用它时,它应该已经在控制台中被炸毁了,因为destroy不是jQuery方法.我在这里想念什么吗?

The page you shared doesn't appear to contain the destroy calls you reference in your code sample, but if they were included you should have seen an uncaught TypeError "undefined is not a function". The reason: You're calling $(this).destroy() instead of this.destroy(). destroy is a function on a Waypoint instance. When you try to call it on a jQuery object, which $() will return, it should have blown up on you in the console because destroy is not a jQuery method. Am I missing something here?

这篇关于使用.destroy();带有Waypoint,但仅在一个对象上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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