/* scrollup v1.0.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) { // settings var settings = { 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: 'top', // text for element activeoverlay: false // set css color to display scrollup active point, e.g '#00ffff' }; // load settings if (options) { var settings = $.extend(settings, options); } // shorthand setting names var sn = '#' + settings.scrollname, an = settings.animation, os = settings.animationoutspeed, is = settings.animationinspeed, td = settings.topdistance, st = settings.scrolltext, ts = settings.topspeed, ao = settings.activeoverlay; // create element $('', { id: settings.scrollname, href: '#top', title: st, text: st }).appendto('body'); // minium css to make the magic happen $(sn).css({ 'display': 'none', 'position': 'fixed', 'z-index': '2147483647' }) // active point overlay if (ao) { $("body").append("
"); $(sn + "-active").css({ 'position': 'absolute', 'top': td + 'px', 'width': '100%', 'border-top': '1px dotted ' + ao, 'z-index': '2147483647' }) } // scroll funtion $(window).scroll(function () { // fade animation if (an === "fade") { $(($(window).scrolltop() > td) ? $(sn).fadein(is) : $(sn).fadeout(os)); } // slideup animation else if (an === "slide") { $(($(window).scrolltop() > td) ? $(sn).slidedown(is) : $(sn).slideup(os)); } // no animation else { $(($(window).scrolltop() > td) ? $(sn).show(0) : $(sn).hide(0)); } }); // back to the top $(sn).click(function (event) { $('html, body').animate({scrolltop: 0}, ts); return false; }); }; // end scrollup function }(jquery));