I recently had to work on creating a simple parallax function for some background images on a full-width page. I had seen the parallax at work at sites like Nike’s Better World (which doesn’t seem to be there anymore) and thought it would be way too over the top to implement on any site I’d be a part of, however, with improving technology and forms of parallax becoming more renowned people are expecting to see a little of its magic on websites these days.
(I think it’s increase in awareness may also have boomed with the iOS7 update – for those who have images placed into their phone’s background.)
Anyway, thankfully inserting Parallax code into an existing site isn’t too difficult. I’m appreciative of the crew over at NetTuts with sharing some simple Parallax code as all I did was refactor this so that it didn’t really rely on the data attributes.
So to use my code simply:
- Create a div with a class tag for whatever you want to use for your Parallax images on your site
- Change the name of the class’ code I have from
.CLASS-OF-PARALLAX-IMAGE-HEREto whatever you have inserted into your HTML
- Set your div’s CSS height property
- …and that’s it!
The script will Parallax the image from top to bottom as you scroll through the window’s viewport. If you want the Parallax to be less intense when you scroll make the div height bigger, if you want the Parallax effect to be more intense make the div height smaller… you get the picture.
The code will similarly work for multiple images containing the same class tag and will also ensure images that appear near the end of the document go from 0% to 100% even though the window viewport has not scrolled to the end of the image.
Anyway, thanks again to Mohiuddin Parekh for the awesome tutorial which helped me to get started, and here’s my resulting code:
In Microsoft Word you can control whether or not you want to see the white space characters in your document. This helps to check you haven't incorrectly inserted a tab where a space should have gone...
Very similar to our previous article on how to make a header row in Google Sheets, in this article we'll show how you can lock a column in Google Sheets. To lock a column in Google Sheets easily...