将Javascript函数链接到返回jQuery对象的jQuery函数

Chaining Javascript function off jQuery function that returns a jQuery object

本文关键字:jQuery 函数 对象 返回 Javascript 链接      更新时间:2023-09-26

我在从TimeCircle jQuery插件链接javascript函数时遇到问题。总之,这个插件创建了一个计时器,我想在计时器达到0时调用一个函数。在文档中,他们提供了一个内置函数end(),当计时器达到0时会自动调用该函数。文档只向我展示了如何链接jQuery函数:

$(".example").TimeCircles().end().fadeOut(); 

这是文件中所说的:end() To allow you to chain TimeCircles to other jQuery functions, you can use the end() function. The end function returns the jQuery object and allows you to trigger jQuery function as desired.

TimeCircle的倒计时结束后,我想完成这样的事情:

$(".example").TimeCircles().end(function() { console.log("timer ended") });

但是,函数在结束时永远不会被调用。有人知道我如何链接自己的javascript函数吗?

以下是插件文档的链接-http://git.wimbarelds.nl/TimeCircles/readme.php

end()函数看起来像是在创建TimeCircles时被调用一次。看起来做你想做的事情的方法是使用addListener函数,如下所示:

    $(".example.stopwatch").TimeCircles().start().addListener(function (unit, value, total) { if (total === 0) {console.log('timer ended');}});

这里有一个JS小提琴,展示你想要的东西https://jsfiddle.net/etzouox4/2/