How to make a checkbox in jQuery block an existing sliding window from moving, and then unlock it by unchecking it?

I am very new to jQuery, but I'm starting to get it.

My question is: How do I make a checkbox in jQuery block an existing sliding window function from moving, and then unlock it by unchecking it? So basically turn on / off an existing function in my project called - #navigate

Any help would be greatly appreciated!

+4
source share
1 answer

Suppose you have the following checkbox selected:

<input type='checkbox' id='stopNavAnim' /> 

You can determine if it is checked like this:

 $('#stopNavAnim').is(':checked'); 

As for managing your specific animation, it really depends on how you #navigate your #navigate . You could just add

 if ($('#stopNavAnim').is(':checked')) return; 

to the places where the animation will be launched. If you are having problems with this, submit the code that you use for the animation.

A terrible jsbin example is available .

Another option would be to bind to the "change" event on the checkbox and call another function to stop / start the animation:

 $('#stopNavAnim').bind('change', function() { if ($(this).is(':checked')) stopAnim(); else startAnim(); }); 
+3
source

Source: https://habr.com/ru/post/1308699/


All Articles