Storing the initial position of the fixed element
Before we can fix the element in place, we'll need to know where that place is. In this task we'll obtain the current starting position of the <aside>
element that we're going to be fixing in place.
Engage Thrusters
In fixed-sidebar.js
we should start with the following code:
$(function() { });
We can cache a couple of jQuery-selected elements at the top of our function, and to store the initial position of the fixed element, we can then add the following code within the function we just added:
var win = $(window), page = $("html,body"), wrapper = page.find("div.wrapper"), article = page.find("article"), fixedEl = page.find("aside"), sections = page.find("section"), initialPos = fixedEl.offset(), width = fixedEl.width(), percentWidth = 100 * width / wrapper.width();
Objective Complete - Mini Debriefing
We've used the same outer wrapper for our code that we used in the first project. As I mentioned then, it...