fixed animation scrolling trigger and refactored code for readability