0

I am struggling with jQuery and cannot seem to find any solution from web searching nor from experimenting myself.

I need to change the speed of an animation according to the value of a radio button, but my code doesn't work. I even tried to reload the page after checking a radio button then putting its value as the speed, but nothing. I'm kind of lost.

Here's the fiddle of what I'm trying to do.

Thanks in advance.

2 Answers 2

2

You are using a constant value 1400 as the duration... this essentially is the speed, as it is the amount of time it takes to get from start to finish.

EDIT:

Now that you are trying 'speed' as your duration, keep in mind that getting the value from the radial returns you a string. You need to convert it to a number with parseInt(speed) before you can use it as the animation duration.

JSFiddle

2
  • :/ i dont know what's happening. i set it to "speed" when i wrote it. but still it doesn't work anyway.
    – OlsiOdo
    Jul 24, 2014 at 21:53
  • 1
    Ah, in that case it's because speed is a string value, and the parameter is expecting a number. Try using parseInt(speed) instead.
    – Lochemage
    Jul 24, 2014 at 21:57
0

Your the value of speed is a string. I used parseInt() to change it to int

$('.box').click(function(){
    var speed = $("input:radio[name ='speed']:checked").val();
    $(this).animate({left: "+=300" }, parseInt(speed));
});
1
  • yeah, i wrote "speed" but i dont know why it's set to 1400
    – OlsiOdo
    Jul 24, 2014 at 21:54

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.