This function will be used to animate the cloud's movement across the viewport by getting the element's left position and adding to it incrementally on each scroll. It receives in the function call the variable's element and increment. In the function, you will first work with the element's style left property using the split method on the string p
.
We need to add some failsafe fallback here in case the value is not a number. This could happen if there isn't any value for the style's left property. To verify whether this value is a number, first use the parseInt
function on the value you just created and check that it's not NaN
(Not a Number). If this logical step passes, return the value of the bounding rectangle's left property of the element, with the string px
appended to it.
If the logical test fails, using else
, get the integer value of the element's style left property by using the parseInt
function and then the absolute value of it, and then add the increment...