销毁免费墙实例 [英] Destroy a freewall instance

查看:126
本文介绍了销毁免费墙实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 jquery-Freewall插件,我想知道如何销毁

I am using the jquery-Freewall-plugin and i want to know how to destroy an instance of it.

我写了一个小例子供大家理解:

I wrote a little example for you people to understand:

var startFreewall = function(){
    $(function() {
        var wall = new freewall("#freewall");
        wall.reset({
            selector: '.brick',
            animate: false,
            cellW: 160,
            cellH: 160,
            delay: 50,
            onResize: function() {
                wall.refresh($('div.col.rood.bart').width()+100, $('div.col.rood.bart').height()+100);
            }
        });
        // caculator width and height for IE7;
        wall.fitZone($('div.col.rood.bart').width()+100 , $('div.col.rood.bart').height()+100);
    });
}
startFreewall();

$('button').click(function(){
    'destroy the function so i can call it again'
});


推荐答案

以下说明如何移除所有外挂程式元素如果插件不包含destroy方法:

Here’s how to remove all instances of all plugins from an element if the plugin does not include a destroy method:

$.removeData($element.get(0));

这不会删除绑定的事件。你必须单独做。
如果你想要删除的插件有命名空间的事件,你会幸运:

This will not remove the bound events. You have to do that separately. If the plugin you’re trying to remove has namespaced events, you’re in luck:

// Remove namespaced events added using .on()
$element.off('pluginNamespace');
// Remove namespaced events added using .bind()
$element.unbind('.pluginNamespace');

如果没有,您可以检查附加到元素的所有事件:

If not, you can examine all of the events attached to an element:

console.log(
    '$element events:', 
    $._data($element.get(0), 'events')
);

这里是一个方便的函数:

Here’s all wrapped up in a handy function:

var destroyUnwantedPlugin = function($elem, eventNamespace) {
    var isInstantiated  = !! $.data($elem.get(0));

    if (isInstantiated) {
        $.removeData($elem.get(0));
        $elem.off(eventNamespace);
        $elem.unbind('.' + eventNamespace);
    }
};

您需要将实例传递给上述函数:

You need to pass the instance to above function:

$('button').click(function(){
    destroyUnwantedPlugin(wall);
});

希望它可以工作:)

这篇关于销毁免费墙实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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