6

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! :)

2
  • 1
    You need to unbind any events and remove any nodes or classes added by the plugin. What do you want the end result to be? Do you want the images to still display, just not animate? Commented Mar 1, 2014 at 19:23
  • Yes, I want the images to still display without animation. Commented Mar 1, 2014 at 19:43

5 Answers 5

6
+50

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());
Sign up to request clarification or add additional context in comments.

2 Comments

Its not perfect but its good enough for me, thanks for your time :)
you are welcome :) , If you find a better workaround please post it
1

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

$('#ri-grid').data('gridrotator').$items.length = 0;

Comments

1

The gridrotator plugin does not seem to have a builtin disable feature.

Using .remove() will remove all bound events and jQuery data associated with the elements that are removed.

Try removing the element and inserting it back in its place.

$("button#destroy").click(function(){

  // remove plugin class so it doesn't rebind
  $("#ri-grid").removeClass("gridrotator");

  var $prev = $("#ri-grid").prev();
  if($prev.length) {

    // put back between siblings if necessary
    $prev.append($("#ri-grid").remove());

  } else {

    // or just re-add to its parent
    var $parent = $("#ri-grid").parent();
    $parent.prepend($("#ri-grid").remove());

  }

});

4 Comments

Thank you so much! but works only on click and then the animation restarts.
I'll try to create the destroy method for this plugin.
updated to remove 'gridrotator' class so the plugin doesn't rebind to it after its removed and inserted
Any progress? I have tried this but it only cuts out the animation before it starts again.
0

Hope this will make you smile -

<button id="destroy">Disable Effect</button>

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

Know more on .stop() function - http://api.jquery.com/stop/

Comments

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

1 Comment

Thank you! but doesn't stop the animation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.