Created
September 22, 2012 06:41
-
-
Save mrsinguyen/3765381 to your computer and use it in GitHub Desktop.
Scrolltop menu
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
<div id="scrolltop"> | |
<span></span> | |
</div> |
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
(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