Hello everyone,
java script is a new area for me but i’m working my way through it. I’m stuck right now and just can’t get any further.
I would like the background to change depending on the position when scrolling. The whole should have several color gradients and a smooth transition between the changes. I get the gradients, but not the smooth transition.
var body = document.getElementsByTagName(‘body’)[0];
body.style.background = ‘linear-gradient(0deg, rgba(63,94,251,1) 0%, rgba(214,20,20,1) 100%)’;
// trigger this function every time the user scrolls
window.onscroll = function (event)
{
var scroll = window.pageYOffset;
if (scroll < 300) {
body.style.background = 'linear-gradient(0deg, rgba(63,94,251,1) 0%, rgba(28,255,9,1) 100%), transition: background 5s ease';
}
else if (scroll >= 300 && scroll < 600) {
body.style.background = 'linear-gradient(0deg, rgba(63,94,251,1) 0%, rgba(171,156,46,1) 100%), transition: background 5s ease';
}
else if (scroll >= 600 && scroll < 1200) {
body.style.background = 'linear-gradient(0deg, rgba(63,94,251,1) 0%, rgba(46,161,171,1) 100%), transition: background 5s ease';
}
else if (scroll >= 1200 && scroll < 1800) {
body.style.background = 'linear-gradient(0deg, rgba(63,94,251,1) 0%, rgba(171,46,89,1) 100%)';
}
else if (scroll >= 1800 && scroll < 3000){
body.style.background = 'linear-gradient(0deg, rgba(63,94,251,1) 0%, rgba(171,46,89,1) 100%)';
}
}
;