0

Is there any way to stop jQuery css() function. I know that I can stop jQuery animate() function with jQuery.stop() function. But I don't know how to stop css() function. Thanks!

11
  • 1
    What do you mean "stop function"? Commented Nov 14, 2013 at 13:37
  • I mean, to stop $(selector).css({}) function like in animate() function before finishing the process. Commented Nov 14, 2013 at 13:38
  • What are you actually trying to do? Commented Nov 14, 2013 at 13:39
  • 1
    are you trying to stop css animations? Commented Nov 14, 2013 at 13:39
  • I assume you're referring to a CSS animation? Commented Nov 14, 2013 at 13:39

2 Answers 2

2

You cant actually do what you want with only class. But here what you can do :

$('button').click(function(){
    $('span').width($('span').width());
})

Of course you'll need to adjust for your code. The goal here is to set the width to override the style sheet width on button click.

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

2 Comments

yes, it works! Thanks! But I have another problem which isn't related with this problem. When I stop animation and again click to continue button to set again css animation, it delays few milliseconds (seconds) before continuing.
I can't tell why since i cant see the code, but maybe your code take a lot of juice and that's why it is delayed...
1

If you want to stop animating mid way you can do it buy storing the current width value when you click the button and applying the width to the <span>.

Please see my JsFiddle example.

JQuery

$('span').animate({'width': '100%'}, 5000)

$(document).on('click', 'button', function(){
    var width = $('span').width();

    $('span').stop(true, true).width(width);
});

1 Comment

Thanks! Really nice example! ;-)

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.