refactor animation script, fix animation in safari