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!
-
1What do you mean "stop function"?Karl-André Gagnon– Karl-André Gagnon2013-11-14 13:37:59 +00:00Commented Nov 14, 2013 at 13:37
-
I mean, to stop $(selector).css({}) function like in animate() function before finishing the process.Ziyaddin Sadygly– Ziyaddin Sadygly2013-11-14 13:38:57 +00:00Commented Nov 14, 2013 at 13:38
-
What are you actually trying to do?AfromanJ– AfromanJ2013-11-14 13:39:09 +00:00Commented Nov 14, 2013 at 13:39
-
1are you trying to stop css animations?Pranav Gupta– Pranav Gupta2013-11-14 13:39:34 +00:00Commented Nov 14, 2013 at 13:39
-
I assume you're referring to a CSS animation?Rory McCrossan– Rory McCrossan2013-11-14 13:39:57 +00:00Commented Nov 14, 2013 at 13:39
|
Show 6 more comments
2 Answers
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.
2 Comments
Ziyaddin Sadygly
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.
Karl-André Gagnon
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...
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
Ziyaddin Sadygly
Thanks! Really nice example! ;-)