首页 > javascript > arrival.js没有检测到注入的元素

arrival.js没有检测到注入的元素 (arrival.js not detecting injected element)

2018-12-18 javascript

问题

我正在尝试使用arrival.js库来检测元素何时被注入到体内或者在某种程度上可用DOM。这是我在JS中尝试的代码:

setTimeout(function() {
    $("body").append("<p class = 'foo'>Yep</p>");
}, 5000);

$(function() {   
    $(document).arrive(".foo", function() {
        alert("hell Yeah");
    });    
});

问题是,元素确实会在5秒后附加到身体上,但警报永远不会出现。知道如何让它按预期工作吗?

这是小提琴

解决方法

删除arrive.min.js资源并使用此cdn链接

https://cdnjs.cloudflare.com/ajax/libs/arrive/2.4.1/arrive.min.js

小提琴

问题

I am trying out the arrival.js library to detect when an element is injected into the body or is somehow available in the DOM. This is the code I am trying in JS:

setTimeout(function() {
    $("body").append("<p class = 'foo'>Yep</p>");
}, 5000);

$(function() {   
    $(document).arrive(".foo", function() {
        alert("hell Yeah");
    });    
});

Problem is, the element does get appended to the body after 5 seconds, but the alert never comes up. Any idea how to make it work as expected?

This is the fiddle.

解决方法

Remove arrive.min.js in resource and use this cdn link

https://cdnjs.cloudflare.com/ajax/libs/arrive/2.4.1/arrive.min.js

fiddle

相似信息