/* scrollUp v1.1.0 Author: Mark Goodyear - http://www.markgoodyear.com Git: https://github.com/markgoodyear/scrollup Copyright 2013 Mark Goodyear Licensed under the MIT license http://www.opensource.org/licenses/mit-license.php Twitter: @markgdyr */ ;(function($) { $.scrollUp = function (options) { // Defaults var defaults = { scrollName: 'scrollUp', // Element ID topDistance: 300, // Distance from top before showing element (px) topSpeed: 300, // Speed back to top (ms) animation: 'fade', // Fade, slide, none animationInSpeed: 200, // Animation in speed (ms) animationOutSpeed: 200, // Animation out speed (ms) scrollText: 'Scroll to top', // Text for element scrollImg: false, // Set true to use image activeOverlay: false // Set CSS color to display scrollUp active point, e.g '#00FFFF' }; var o = $.extend({}, defaults, options), scrollId = '#' + o.scrollName; // Create element $('', { id: o.scrollName, href: '#top', title: o.scrollText }).appendTo('body'); // If not using an image display text if (!o.scrollImg) { $(scrollId).text(o.scrollText); } // Minium CSS to make the magic happen $(scrollId).css({'display':'none','position': 'fixed','z-index': '2147483647'}); // Active point overlay if (o.activeOverlay) { $("body").append("
"); $(scrollId+"-active").css({ 'position': 'absolute', 'top': o.topDistance+'px', 'width': '100%', 'border-top': '1px dotted '+o.activeOverlay, 'z-index': '2147483647' }); } // Scroll function $(window).scroll(function(){ switch (o.animation) { case "fade": $( ($(window).scrollTop() > o.topDistance) ? $(scrollId).fadeIn(o.animationInSpeed) : $(scrollId).fadeOut(o.animationOutSpeed) ); break; case "slide": $( ($(window).scrollTop() > o.topDistance) ? $(scrollId).slideDown(o.animationInSpeed) : $(scrollId).slideUp(o.animationOutSpeed) ); break; default: $( ($(window).scrollTop() > o.topDistance) ? $(scrollId).show(0) : $(scrollId).hide(0) ); } }); // To the top $(scrollId).click( function(event) { $('html, body').animate({scrollTop:0}, o.topSpeed); event.preventDefault(); }); }; })(jQuery);