Skip to content

Instantly share code, notes, and snippets.

@hellofromtonya
Created July 6, 2014 11:04
Show Gist options
  • Save hellofromtonya/f0b200b357123baf8da8 to your computer and use it in GitHub Desktop.
Save hellofromtonya/f0b200b357123baf8da8 to your computer and use it in GitHub Desktop.
Scroll to the Top floating icon feature - jQuery script
/*
* JavaScript|jQuery functions
*
* Load into child namespace
*
* @category LUNARWP Core
* @package Assets
* @subpackage JS
* @since 1.0.0
* @author LUNARWP
* @license http://www.opensource.org/licenses/gpl-license.php GPL v2.0 (or later)
* @link http://lunarwp.com/
*/
(function($){
'use strict';
var lunarwpCore = {
pageLoad: function() {
},
scrollToTop: function() {
$(window).scroll(function(){
if ($(this).scrollTop() > 100) {
$('.scrollup').fadeIn();
} else {
$('.scrollup').fadeOut();
}
});
$('.scrollup').click(function(){
$("html, body").animate({ scrollTop: 0 }, 600);
return false;
});
},
smoothScroll: function() {
$('a[href*=#]:not([href=#])').click(function()
{
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
if (target.length) {
$('html,body').animate({
scrollTop: target.offset().top
}, 1000);
return false;
}
}
});
},
// Time to initialize the methods
//
// @since 1.0.0
//
// @function
//
ready: function() {
lunarwpCore.pageLoad();
lunarwpCore.scrollToTop();
lunarwpCore.smoothScroll();
}
};
//
// Launch this baby. Blast off
//
// @since 1.0.0
//
// @child
//
$(document).ready(function () {
lunarwpCore.ready();
});
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment