var isAnimated = false; $(window).scroll(function() { var scrollTop = $(window).scrollTop(); if (scrollTop > ($(window).height()) && !isAnimated) { isAnimated = true; smoothRemove('#static-image'); smoothRemove('#static-text'); } else if (scrollTop <= ($(window).height()) && isAnimated) { isAnimated = false; smoothReturn('#static-image'); smoothReturn('#static-text'); } }); function smoothRemove (idname) { $(idname).animate({top: '-200px'}, 1000, function() { $(this).css({ position: 'absolute', top: $(window).height() - 200 + 'px', overflow: 'hidden', display: 'none' }); }); } function smoothReturn (idname) { $(idname).css({ position: 'fixed', top: '-200px', overflow: 'visible', display: '' }).animate({top: '20'}, 1000); } function rotateImage(idname) { let image = document.getElementById(idname); image.style.transform = "rotate(360deg)"; }