If I have 300 functions like this:
function name1() {
alert("1");
}
function name2() {
alert("2");
}
function name3() {
alert("3");
}
Etc all the way to 300, how could I concatenate these all into one function because they are so similar even though each one does have slight differences?
UPDATE:
Sorry, I used example functions because I didn't think it would matter to put my long code in the question, but I think it does matter now, here are the real functions:
function event() {
//paths
var path = document.querySelector('#container #path');
var length = path.getTotalLength();
console.log(path.getTotalLength());
// Clear any previous transition
path.style.transition = path.style.WebkitTransition =
'none';
// Set up the starting positions
path.style.strokeDasharray = length + ' ' + length;
path.style.strokeDashoffset = length;
// Trigger a layout so styles are calculated & the browser
// picks up the starting position before animating
path.getBoundingClientRect();
// Define our transition
path.style.transition = path.style.WebkitTransition =
'stroke-dashoffset 0.4s linear';
// Go!
path.style.strokeDashoffset = '0';
document.getElementById("container").style.visibility = "visible";
};
function event2() {
//paths
var path2 = document.querySelector('#container2 #path_2');
var length = path2.getTotalLength();
console.log(path2.getTotalLength());
// Clear any previous transition
path2.style.transition = path2.style.WebkitTransition =
'none';
// Set up the starting positions
path2.style.strokeDasharray = length + ' ' + length;
path2.style.strokeDashoffset = length;
// Trigger a layout so styles are calculated & the browser
// picks up the starting position before animating
path2.getBoundingClientRect();
// Define our transition
path2.style.transition = path2.style.WebkitTransition =
'stroke-dashoffset 0.45s linear';
// Go!
path2.style.strokeDashoffset = '0';
document.getElementById("container2").style.visibility = "visible";
};
function event3() {
//paths
var path3 = document.querySelector('#container3 #path_3');
var length = path3.getTotalLength();
console.log(path3.getTotalLength());
// Clear any previous transition
path3.style.transition = path3.style.WebkitTransition =
'none';
// Set up the starting positions
path3.style.strokeDasharray = length + ' ' + length;
path3.style.strokeDashoffset = length;
// Trigger a layout so styles are calculated & the browser
// picks up the starting position before animating
path3.getBoundingClientRect();
// Define our transition
path3.style.transition = path3.style.WebkitTransition =
'stroke-dashoffset 0.4s linear';
// Go!
path3.style.strokeDashoffset = '0';
document.getElementById("container3").style.visibility = "visible";
};
window.setTimeout(function() {
event();
}, 1);
window.setTimeout(function() {
event2();
}, 550);
window.setTimeout(function() {
event3();
}, 1100);
So I would have to make changes to them, but the majority of it is the same, so how would I do it given this code? Thanks a lot.
function name( nr ) { alert( nr ); }?