0

I have the following glitch effect applied to a section of my page, however it can be quite distracting. I wish to create a toggle button to disable and re-enable the script.

http://eg-graphics.com/zwooper/EGVGV/Season3/MemoryWall.html

So to call the function I have the following code:

 $( function() {
    $( ".glitch-img" ).mgGlitch({
        destroy : false, // set 'true' to stop the plugin
        glitch: true, // set 'false' to stop glitching
        scale: true, // set 'false' to stop scaling
        blend : true, // set 'false' to stop glitch blending
        blendModeType : 'hue', // select blend mode type
        glitch1TimeMin : 600, // set min time for glitch 1 elem
        glitch1TimeMax : 900, // set max time for glitch 1 elem
        glitch2TimeMin : 10, // set min time for glitch 2 elem
        glitch2TimeMax : 115, // set max time for glitch 2 elem
    });
});

To disable this plugin i need to set it so it's destroy : true.

Where I struggle is that I am unable to recall the function with destroy:true and then again with destroy : false.

Thank you in advance

0

1 Answer 1

2
var toggle=false; 
$("#toggleBut").on("click",function() { 
    toggle=!toggle; 
    $( ".glitch-img" ).mgGlitch({destroy : toggle }); 
});

https://codepen.io/anon/pen/rvMMzw

Sign up to request clarification or add additional context in comments.

2 Comments

Maybe better $("#toggleBut").on("click",function() { $( ".glitch-img" ).mgGlitch({destroy : $('.glitch-img .front-1').length > 0 }); }); ?
@mplungjan 's suggestion was clear in my opinion. Thank you though!

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.