Created
February 9, 2013 15:27
-
-
Save Freyert/4745708 to your computer and use it in GitHub Desktop.
Hide side bar when inactive, shows when mouse enters right screen. Reddit.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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