如何从HTML元素中停止或删除jQuery函数

时间:2015-02-04 16:19:57

标签: javascript jquery html function

我正在附加一个像这样的函数,它会加载页面或再次调用:

function scroller(dist){
    $('#gallery').scrollbox({
        direction: 'h', // vertical or horizontal
        distance: dist // the distance between items
    });
}

然而,当我再次调用此函数时,它的多个实例同时工作。如何停止或删除此功能?在调用滚动条之前,我已尝试将$('#gallery'。)unbind()作为函数的一部分,但这并不起作用。

可以找到滚动条功能here,它用于动画图像库。

1 个答案:

答案 0 :(得分:2)

我要做的是为我将小部件附加到的任何元素添加一个类:

function scroller(dist){
    $('#gallery:not(.scroll-added)').scrollbox({
        direction: 'h', // vertical or horizontal
        distance: dist // the distance between items
    }).addClass("scroll-added");
}