Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable or destroy a jQuery plugin function?

I have a gallery that uses the jQuery gridrotator effect. I want to enable the effect when I click on button "enable effect".

<button id="build">Enable Effect</button>
<script type="text/javascript">
    $("button#build").click(function(){
        $('#ri-grid').gridrotator();
    });
</script>

And the enablig effect works fine (see this test). To disable effect there is no a destroy method for this plugin. So I tried to return to false the function but doesn't work.

<button id="destroy">Disable Effect</button>
<script type="text/javascript">
    $("button#destroy").click(function(){
        $('#ri-grid').gridrotator(function(){
            return false;
        });
    });
</script>

How can I disable or destroy this function?
Thank you so much for any help! :)

like image 610
Mustapha Aoussar Avatar asked Mar 01 '14 19:03

Mustapha Aoussar


2 Answers

I made and tested a good workaround not the perfect solution but it worked. simply remove the item from Dom tree then reload it

        $('#ri-grid').html($('#ri-grid').html());
like image 61
Antoine Raoul Iscaros Avatar answered Sep 28 '22 09:09

Antoine Raoul Iscaros


Maybe there is a better way, but this hack seems to work:

$('#ri-grid').data('gridrotator').$items.length = 0;
like image 25
VisioN Avatar answered Sep 28 '22 10:09

VisioN