I have redone my original Percent Count down project.
To a version that uses a Symbol which is controlled and configured using JS. ( Only counting up )
The JS code is small but easy to configure for each instance of the Symbol.
Each Instance of the Symbol is given a a Unique Element ID ( using the inspector )
Each Symbol instance is started on the Main Timeline of the Project by it's own Symbol Action. ( Start Timeline 'Main Timeline' )
In the JS.
You configure for each Instance using simple if clauses .
//---- Set up per display
var timeToCount, maxPercent;
if (element.id == 'percent100' ) {
timeToCount = 10; //---seconds
maxPercent = 100; //---max Percent
}
if (element.id == 'percent75' ) {
timeToCount = 5; //---seconds
maxPercent = 75; //---max Percent
}
Notice I just get each Symbol Instance's id using element.id. This is because the id is now passed along when the Symbol Action fires. ( Brilliant )
The JS will be run by all of the Symbol Instance you have given a Symbol Action to run. because the Symbol has its own Action on it's main timeline to run the Javascript.
Now that we have configured for each Symbol instance. Each one will only run the rest of the JS using it's settings.
var thisWidth = 0; //-- width increment
var countDownTimerWidth = $('#'+ element.id +' .countDownTimer1').width(); //-- get width of bar.
var thisFire = setInterval(function(){
thisWidth += (countDownTimerWidth /100) ; //-- workout increment size
var thisPercent = Math.floor((thisWidth/ countDownTimerWidth * 100 )); //-- calculate current percentage of bar
if (thisPercent >= maxPercent) { //-- stop at pecentage
clearInterval( thisFire);
}
$('#'+ element.id +' .countDownTimer1').html("%" + thisPercent) ; //-- set progress text
$('#'+ element.id +' .percentBar').width(thisWidth); //-- set progress bar width
}, timeToCount * 10) ;
(
I have used JQuery with this project, originally I did it all in native JS but it is much simpler to get individual class instances with JQuery than it is with JS, where you would need more repeating code and have to use indexes . i.e [0]
)
This example has two instances. One set to stop at 75% and run in 5 seconds. The Other to Stop at %100 and run in 10 seconds
Duration PercentCounterJQShortCode.hypetemplate.zip (51.7 KB)