/** * Escrolltotop jquery back to top plugin, smoothing back to top, * * Parameter settings * Startline: To return the top button from the top of the distance * Scrollto: Scroll to the distance from the top, or the position of an ID element * Scrollduration: Smooth scrolling time * Fadeduration: Fade time eg:[500, 100] [0] fade in, [1] fade out * controlhtml:html Code * ClassName: Style name * TitleName: Return to the top title attribute * OffsetX: Back to top right offset position * OffsetY: Back to top bottom offset position * Anchorkeyword: Cat point Link * Eg: * $.scrolltotop ({ * scrollduration:1000 * }); */ (function ($) { $.scrolltotop = function (options) { Options = Jquery.extend ({ startline:100,//Appearance return top button distance from top scrollto:0,//scroll to the distance from the top, or the position of an ID element scrollduration:500,//Smooth scrolling time Fadeduration: [500, 100],//Fade out time, [0] fade in, [1] fade out controlhtml: ' <a href= ' javascript:; ><b> back to top ↑</b></a> ',//html code ClassName: ',//style name TitleName: ' Back to top ',//back to top title property Offsetx:5,//back to top right offset position Offsety:5,//back to top bottom offset position Anchorkeyword: ' #top ',//Cat dot Link }, Options);
var state = { Isvisible:false, Shouldvisible:false };
var current = this;
var $body, $control, $cssfixedsupport;
var init = function () { var iebrws = document.all; $cssfixedsupport =!iebrws | | Iebrws && Document.compatmode = "Css1compat" && window. XMLHttpRequest $body = (window.opera)? (Document.compatmode = = "Css1compat" $ (' HTML '): $ (' body ')): $ (' html,body '); $control = $ (' <div class= "' +options.classname+ '" id= "Topcontrol" > ' + options.controlhtml + ' </div> '). CSS ({ Position: $cssfixedsupport? ' Fixed ': ' absolute ', Bottom:options.offsety, Right:options.offsetx, opacity:0, Cursor: ' pointer ' }). attr ({ Title:options.titleName ). Click (function () { Scrollup (); return false; }). Appendto (' body '); if (document.all &&!window. XMLHttpRequest && $control. Text ()!= ') { $control. CSS ({ Width: $control. Width () }); } Togglecontrol (); $ (' a[href= ' + Options.anchorkeyword + ' "]"). Click (function () { Scrollup (); return false; }); $ (window). bind (' Scroll resize ', function (e) { Togglecontrol (); }) return to current; };
var scrollup = function () { if (! $cssfixedsupport) { $control. CSS ({ opacity:0 }); } var dest = isNaN (Options.scrollto)? parseint (Options.scrollto): Options.scrollto; if (typeof dest = = "string") { Dest = JQuery (' # ' + dest). length >= 1? JQuery (' # ' + dest). Offset (). top:0; } $body. Animate ({ Scrolltop:dest }, Options.scrollduration); }; var keepfixed = function () { var $window = jQuery (window); var controlx = $window. ScrollLeft () + $window. Width () -$control. Width ()-options.offsetx; var controly = $window. ScrollTop () + $window. Height () -$control. Height ()-options.offsety; $control. CSS ({ Left:controlx + ' px ', Top:controly + ' px ' }); }; var Togglecontrol = function () { var scrolltop = jQuery (window). scrolltop (); if (! $cssfixedsupport) { This.keepfixed () } state.shouldvisible = (scrolltop >= options.startline)? True:false; if (state.shouldvisible &&!state.isvisible) { $control. Stop (). Animate ({ Opacity:1 }, Options.fadeduration[0]); State.isvisible = true; else if (state.shouldvisible = = False && state.isvisible) { $control. Stop (). Animate ({ opacity:0 }, options.fadeduration[1]); State.isvisible = false; } };
Return init (); }; }) (JQuery); |