Skip to content

Instantly share code, notes, and snippets.

@mrsinguyen
Created September 22, 2012 06:41
Show Gist options
  • Save mrsinguyen/3765381 to your computer and use it in GitHub Desktop.
Save mrsinguyen/3765381 to your computer and use it in GitHub Desktop.
Scrolltop menu
<div id="scrolltop">
<span></span>
</div>
(function($) {
Drupal.behaviors.asaleoScrollTop = {
attach: function (context, settings) {
$(window).scroll(function() {
// Check scrollbar is top?
if($(this).scrollTop() != 0) {
// Fadein
$('#scrolltop').fadeIn('slow');
} else {
// Fadeout and remove class active
$('#scrolltop').fadeOut('slow');
$('#scrolltop span').removeClass("active");
}
});
$("#scrolltop").hover(
//Mouseover, add hover class to span
function () {
$('#scrolltop span').addClass("hover");
},
//Mouseout, remove the hover class
function () {
$('#scrolltop span').removeClass("hover");
}
).click(function() {
// Scroll to top when click and add an active class
$('body,html').animate({
scrollTop:0
},400);
$('#scrolltop span').addClass('active');
});
}
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment