While working on a project (We’ll be announcing soon!), our design team wanted a nice color-changing background. Now, we know we could have used a static gradient, or simply faded between sections, but we thought it would be cool if the background changed as the user scrolled down the page, in a fixed manner. Usually when we meet a challenge like this, the first thing we do is check to see if anyone else has already done it, and in no time we found this jsfiddle: http://jsfiddle.net/cgspicer/V4qh9/. It’s great, but we needed a bit more. The current version only supports fades between two colors so we forked the code and expanded on it a little bit.

 

colorscroll

Installing

If you’d like to use this method for your next project, you’ll need jQueryjquery.color-2.1.0.js, and the bits of HTML/CSS/JS included in this jsfiddle: http://jsfiddle.net/jguffey/mxkx9j2o/.

Make it your own.

In the fiddle, we use `<section>` elements to mark the content boundaries, but you can use any element you want by changing the selector on line 8, and the corresponding CSS and HTML. The array of strings in the call to `scrollColors` (line 16) is where we store the colors we’d like to transition to. Remember to change the CSS background-color property for body (our color-change target) to match the first element in this array, or you’ll still get the bright pink color when the page first loads.

Thanks to the jQuery Color plugin, hex, rgb, and even rgba values are allowed. This can yield some cool effects when layered over an image or video. The alpha channel in RGBA is animated just like the other color channels, so you could have a sold color change opacity with scroll.

Enjoy!

 

Featured On

Inc Magazine Logo  

Sitepoint logo  

CSS Tricks logo   

webdesignerdepot logo   WPMU DEV logo   

and many more!

Where are we hosted?

This site is proudly powered by FAST VPS InMotion Servers and given an insane speed thanks to MaxCDN!

Web Hosting MaxCDN - Speed up your website

Advertise on CollectiveRay.com

CollectiveRay (formerly known as DART Creations) is interested in developing partnerships with mutual benefit. If you like the stuff we publish and would like to develop a relationship, we'd be happy to hear from you. Go on - drop us a line - we'd love to hear from you :-)

New! DIVI 3.1 WordPress Template + PageBuilder

You'll surely create a perfect website with Divi 3.1!

Get an exclusive 20% OFF for CollectiveRay visitors until

Divi 3

 

The Outstanding HungryJPEG Bundles

AWESOMENESS! Bundles of premium font + graphic packs at more than 96% OFF!  Get this bundle for just $29 - This month ONLY!

The Hungry JPEG Awesome font bundles

 

Disclosure: CollectiveRay is funded personally out of pure passion for helping people working with websites. We do however generate some income through recommendations of products. This means if you click on a link and purchase an item we link to, we will receive a small sum out of that sale.

who are we?

CollectiveRay is run by David Attard - working in and around the web design niche for more than 12 years, we provide actionable tips for people who work with and on websites. We also run DronesBuy.net - a website for drone hobbyists.

David attard

Follow us on Social

Follow us on Facebook   Follow us on Google+   Subscribe to our RSS Feed   Follow us on Twitter