If the previous condition is true, we need to collect the SVG icons in an array and then get the class of each one. Each class will behave differently. Go through another loop that gathers the current row element's child elements identified by the tag name I. And then loop through each of those children's list of classes collected by the classList method. I will show you how this will look before I tell you what we will do with it. Take a look at the loop in a loop in a loop in this code sample:
function getMovingElements(callback){
for (var i = 0;i<document.getElementsByClassName("row").length; i++)
{
if((window.pageYOffset + (window.innerHeight)) > document.getElementsByClassName("row")[i].offsetTop && (window.pageYOffset) < (document.getElementsByClassName("row")[i].offsetTop + (window.innerHeight/2*3)))
{
for (j = 0; j < document.getElementsByClassName("row")[i].getElementsByTagName("i").length; j++)
{
for (k = 0; k < document.getElementsByClassName("row")[i].getElementsByTagName("i")[j].classList.length; k++)
{
//Do some thing here
}
}
}
}
}Inside the nested loop, we will use a conditional set of tests in a switch block to determine what to do. If an element has made it inside the nested conditional statement, we can assume it is in the viewport, so now we need to determine what to do with it.
The types of elements we are dealing with are the moving objects of our project. The clouds (fa-cloud), plane (fa-plane), moon (fa-moon-o), birds (fa-twitter), and whatever else you would want to add. In the switch block, get the current item in the loop of the classList array, and list these cases of results: fa-cloud, fa-plane, fa-moon-o, and fa-twitter. In the case of fa-cloud, we will do something entirely different instead of using the callback we sent earlier.
In the fa-cloud case, call a function named cloudCall, with the current element identified by the I tag name. In the cases of fa-plane, fa-moon-o, and fa-twitter, send the element identified by the i tag name and an integer for the velocity to the callback. Send 3 for fa-plane, 6 for fa-moon-o, and 2 for fa-twitter . Look at this code sample:
Switch (document.getElementsByClassName("row")[i].getElementsByTagName("i")[j].classList[k])
{
case 'fa-cloud':
cloudCall(document.getElementsByClassName("row")[i].getElementsByTagName("i")[j]);
break;
case 'fa-plane':
callback(document.getElementsByClassName("row")[i].getElementsByTagName("i")[j],3);
break;
case 'fa-moon-o':
callback(document.getElementsByClassName("row")[i].getElementsByTagName("i")[j],6);
break;
case 'fa-twitter':
callback(document.getElementsByClassName("row")[i].getElementsByTagName("i")[j],2)
break;
default:
;
}