Skip to content

Instantly share code, notes, and snippets.

@rawaludin
Created November 18, 2012 06:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rawaludin/4103884 to your computer and use it in GitHub Desktop.
Save rawaludin/4103884 to your computer and use it in GitHub Desktop.
jquery: toTop watcher
<script type="text/javascript">
<!--//--><![CDATA[//><!--
jQuery(document).ready(function($) {
$(window).scroll(function() {
if($(this).scrollTop() != 0) {
$("#toTop").fadeIn();
} else {
$("#toTop").fadeOut();
}
});
$("#toTop").click(function() {
$("body,html").animate({scrollTop:0},800);
});
});
//--><!]]>
</script>
CSS:
#toTop {
background: url("images/backtotop-arrow.png") no-repeat scroll 0% 0% transparent;
width: 51px;
height: 50px;
position: fixed;
cursor: pointer;
bottom: 60px;
right: 10px;
display: none;
z-index: 100;
opacity: 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment