window.onscroll = function() { var a = document.documentElement.scrollTop || document.body.scrollTop; bg.style.marginTop = -(bgHeight - height)*(a/(scrollHeight-height))+'px' }