1

I am using this JQuery gauge.

I am trying to create some sort of set animation, so i.e. 100 then after 300ms show 97, then after 200ms show 110, etc.

I would like to be totally undependable on that input field (it would be thrown out at one point), So how would I able to just use an array of set numbers with a constant delay where the animation plays out the speed based on the numbers in the array and delaying after each number by the delay constant (let's say 300ms.)

Thanks.

I've tried to select the element and apply a set value like this: $("#myValues").myfunc({divFact:20,eventListenerType:'keyup'}).val(100), but it just places the number there with no result, it's using eventListenerType:'keyup' and my val function is def. not sending a keyup after the 100.

Here is a Fiddle

1

3 Answers 3

1

You can iterate over an array and set the value of the input field depending of the value in the index:

$("#myValues").myfunc({
  divFact: 10
});

var time = 0;
$.each([ 100, 90, 80, 70 ], function( index, value ) {
 setTimeout( function(){ $("#myValues").val(value).change(); }, time)
 time += 1000;
});

To delay each iteration you could use a setTimeout-function wrapped around the setter of the value.

I removed the keyUp event as the plugin has a default value for eventListenerType you can use, but this has to be triggered.

Set the initial value of time to any value you want when you want to delay the first iteration as well.

Example

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

Comments

1

There are 2 problems,

  1. The plugin not returning the object reference in the plugin code so you can't change the value using val() method.
  2. The val() method doesn't trigger the keyup event you need to trigger it programmatically.

You can either add code for returning the object reference or do it like.

var $ele = $("#myValues"); // cache the reference
$ele.myfunc({divFact:20,eventListenerType:'keyup'}); // initialize plugin
$ele.val(100).keyup(); // change value and trigger the event

Working Example

Comments

0

I have changed 2 things in your jsfiddle:

  1. I added a speed parameter to the changePosition method.
  2. I return this at the end of the object initializer.

With some other possible minor improvements. See my jsfiddle

Edit: I did it this way because you wanted to get the input field out of it. This is the way.

Comments

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.