Scrollbar Annotation animation at 100
A quick and dirty scrollbar annotation like in Path for iPhone. based on: http://jsfiddle.net/michaelhue/7NAvm/7/light/
by lovromar
HTML
<div id="scrollbubble"></div>
<div id="bye">
<img src="http://gifs.gifbin.com/072009/1246883685_slingshot_prank.gif" /><span class="msg1">Ooooh, its too late, bye!</span><span class="msg2">Have a nice day !</span>
</div>
<div style="height: 2000px">
<p>Scroll
<br />down
<br />↓ ↓ ↓</p>
<p class="scup">Scroll
<br />up and
<br />save a consultant</p>
</div>
CSS
@import url(http://fonts.googleapis.com/css?family=Questrial);
body {
font: 12px/1.5 Questrial, Helvetica, sans-serif;
position:relative;
}
p {
margin-right: 30px;
/* text-transform: uppercase;*/
text-align: right;
font-size: 70px;
font-weight: bold;
line-height: 1;
color: rgb(200, 200, 200);
}
p.scup {
position: absolute;
bottom: 250px;
right:30px;
}
#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;
}
#bye {
padding: 5px 4%;
background: #000;
color: #fff;
position: fixed;
bottom: -240px;
right: 5px;
height:230px;
width:92%;
text-align:right;
/* display: none;*/
font-size:16px;
}
#bye span {
display:block;
padding:10px 0;
}
#bye img {
width:397px;
float:left;
opacity:0;
}
#bye span.msg1 {
font-size:22px;
opacity:0;
}
#bye span.msg2 {
font-size:30px;
opacity:0;
}
JavaScript
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('ECDC Consultant Ejection Progress (' + Math.round(progress * 100) + '%)')
.fadeIn(100);
//alert(progress);
/* if($(window).scrollTop() == ($('body').height() - $(window).height()))*/
if (progress >= 0.99) {
//alert('fufu');
$('div#bye').animate({
bottom: '0'
}, 88),
$('div#bye > img').animate({
opacity: '1'
}, 2000, function () {
$('div#bye > span.msg1').animate({
opacity: '1'
}, 1000,
function () {
$('div#bye > span.msg2').animate({
opacity: '1'
}, 1000);
return false;
});
});
} else {
$('div#bye').animate({
bottom: -240
}, 88),
$('div#bye > span.msg1').css('opacity', '0');
$('div#bye > span.msg2').css('opacity', '0');
$('div#bye > img').css('opacity', '0');
return false;
}
// Fade out the annotation after 1 second of no scrolling.
if (scrollTimer !== null) {
clearTimeout(scrollTimer);
}
scrollTimer = setTimeout(function () {
$('#scrollbubble').fadeOut();
}, 5000);
});