Skip to content

Instantly share code, notes, and snippets.

@Freyert
Created February 9, 2013 15:27
Show Gist options
  • Select an option

  • Save Freyert/4745708 to your computer and use it in GitHub Desktop.

Select an option

Save Freyert/4745708 to your computer and use it in GitHub Desktop.
Hide side bar when inactive, shows when mouse enters right screen. Reddit.
var sideBarLength, rightSide, winLength, pointerX, sideShowing, transition;
winLength = window.innerWidth || window.innerLength;
sideBar = document.getElementsByClassName('side')[0];
rightSide = winLength - sideBar.clientWidth;
sideShowing = true;
transition = (function () {
var vendors = ["Webkit", "Moz", "ms", "O"], result;
for (var i = 0; i < vendors.length;) {
if (vendors[i] + "Transition" in sideBar.style){
result = vendors[i] + "Transition";
return result;
}
}
return "transition";
})();
sideBar.style[transition] = "width, 2s, ease-in-out";
window.onmousemove = function (event) {
pointerX = event.clientX;
if (sideShowing && pointerX < rightSide) {
window.setTimeout(function () {sideBar.style.width = "0px"}, 2000);
sideShowing = false;
} else {
if (pointerX > rightSide + 200) {
sideBar.style.width = "300px";
sideShowing = true;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment