April 2, 2014

jQuery Variables, Functions, and Conditional Logic

This lesson picks up where our original “Introduction to JavaScript with jQuery” lesson ended. We learn how to use variables, conditional logic and functions to create flexible code.

Link to demo page shown in lesson

Note: The reveal effect shown in this lesson is not terribly useful in real world applications. Most tablets and smartphones cannot run code during the middle of a swipe scroll event so the effect will only run seamlessly on traditional computers / laptops. In short, I wouldn’t necessarily use this effect on a production website, but it is a good playground for the sake of learning more about JavaScript variables, functions, and conditional logic.

Also, I recommend not using jQuery’s “animate” method whenever possible. Instead, you can simply use jQuery to add/remove a class at the desired moments, and instead use CSS transitions or animations. We’ll cover this strategy in future lessons. The jQuery animate method is more dependable in older browsers and devices, but the CSS method provides smoother performance.

Finally, we created the “on scroll reveal” functionality in this lesson from scratch as a learning exercise. If, however you’re interested in a more robust and pre-built solution, be sure to search for the existing jQuery plugin named “jQuery WayPoints.”

Put together a neat page infused with JavaScript awesomeness and want to move it from your computer to online so the world can see your JS chops? The next step is to use a web host to share your site with the world. Learn about web hosts, my favorite one, and how to get a plan for only $5.78 per month.

About the Author

Brad Schiff

Brad Schiff is a front-end developer, designer, and educator who has been building user interfaces for over a decade. He’s done work for Fortune 500 companies, national political campaigns, and international technology leaders. His proudest achievement is helping people learn front-end web development.

Follow Brad on Twitter Subscribe on YouTube

Leave a Reply

Your email address will not be published. Required fields are marked *