Created
December 8, 2011 09:38
-
-
Save Victa/1446570 to your computer and use it in GitHub Desktop.
Scrollbar Annotation (path)
This file contains 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
<div id="scrollbubble"></div> | |
<div style="height: 2000px"> | |
<p>Scroll<br />down<br />↓ ↓ ↓</p> | |
</div> |
This file contains 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
body { | |
font: 12px/1.5 Helvetica, sans-serif; | |
} | |
p { | |
margin-right: 30px; | |
text-transform: uppercase; | |
text-align: right; | |
font-size: 70px; | |
font-weight: bold; | |
line-height: 1; | |
color: rgb(200, 200, 200); | |
} | |
#scrollbubble { | |
display: none; | |
position: fixed; | |
top: 0; | |
right: 20px; | |
z-index: 500; | |
padding: 3px 8px; | |
background-color: #000; | |
color: #FFF; | |
border-radius: 3px; | |
} | |
#scrollbubble:after { | |
content: " "; | |
position: absolute; | |
top: 50%; | |
right: -8px; | |
height: 0; | |
width: 0; | |
margin-top: -4px; | |
border: 4px solid transparent; | |
border-left-color: #000; | |
} |
This file contains 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 scrollTimer = null; | |
$(window).scroll(function() { | |
var viewportHeight = $(this).height(), | |
scrollbarHeight = viewportHeight / $(document).height() * viewportHeight, | |
progress = $(this).scrollTop() / ($(document).height() - viewportHeight), | |
distance = progress * (viewportHeight - scrollbarHeight) + scrollbarHeight / 2 - $('#scrollbubble').height() / 2 | |
; | |
$('#scrollbubble') | |
.css('top', distance) | |
.text('Progress (' + Math.round(progress * 100) + '%)') | |
.fadeIn(100) | |
; | |
// Fade out the annotation after 1 second of no scrolling. | |
if (scrollTimer !== null) { | |
clearTimeout(scrollTimer); | |
} | |
scrollTimer = setTimeout(function() { | |
$('#scrollbubble').fadeOut(); | |
}, 1000); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
// src = http://jsfiddle.net/michaelhue/7NAvm/7/light/