PageSourceSearch

https://www.nabran.ru/js/top-button.js

js nabran.ru collected 2026-10-02 19:50:52 UTC 3,858 bytes, 59 lines download raw bytes

1;(function(d){var k=d.scrollTo=function(a,i,e){d(window).scrollTo(a,i,e)};k.defaults={axis:'xy',duration:parseFloat(d.fn.jquery)>=1.3?0:1};k.window=function(a){return d(window)._scrollable()};d.fn._scrollable=function(){return this.map(function(){var a=this,i=!a.nodeName||d.inArray(a.nodeName.toLowerCase(),['iframe','#document','html','body'])!=-1;if(!i)return a;var e=(a.contentWindow||a).document||a.ownerDocument||a;return d.browser.safari||e.compatMode=='BackCompat'?e.body:e.documentElement})};d.fn.scrollTo=function(n,j,b){if(typeof j=='object'){b=j;j=0}if(typeof b=='function')b={onAfter:b};if(n=='max')n=9e9;b=d.extend({},k.defaults,b);j=j||b.speed||b.duration;b.queue=b.queue&&b.axis.length>1;if(b.queue)j/=2;b.offset=p(b.offset);b.over=p(b.over);return this._scrollable().each(function(){var q=this,r=d(q),f=n,s,g={},u=r.is('html,body');switch(typeof f){case'number':case'string':if(/^([+-]=)?\d+(\.\d+)?(px|%)?$/.test(f)){f=p(f);break}f=d(f,this);case'object':if(f.is||f.style)s=(f=d(f)).offset()}d.each(b.axis.split(''),function(a,i){var e=i=='x'?'Left':'Top',h=e.toLowerCase(),c='scroll'+e,l=q[c],m=k.max(q,i);if(s){g[c]=s[h]+(u?0:l-r.offset()[h]);if(b.margin){g[c]-=parseInt(f.css('margin'+e))||0;g[c]-=parseInt(f.css('border'+e+'Width'))||0}g[c]+=b.offset[h]||0;if(b.over[h])g[c]+=f[i=='x'?'width':'height']()*b.over[h]}else{var o=f[h];g[c]=o.slice&&o.slice(-1)=='%'?parseFloat(o)/100*m:o}if(/^\d+$/.test(g[c]))g[c]=g[c]<=0?0:Math.min(g[c],m);if(!a&&b.queue){if(l!=g[c])t(b.onAfterFirst);delete g[c]}});t(b.onAfter);function t(a){r.animate(g,j,b.easing,a&&function(){a.call(this,n,b)})}}).end()};k.max=function(a,i){var e=i=='x'?'Width':'Height',h='scroll'+e;if(!d(a).is('html,body'))return a[h]-d(a)[e.toLowerCase()]();var c='client'+e,l=a.ownerDocument.documentElement,m=a.ownerDocument.body;return Math.max(l[h],m[h])-Math.min(l[c],m[c])};function p(a){return typeof a=='object'?a:{top:a,left:a}}})(jQuery);
2jQuery.fn.topLink = function(settings) {
3settings = jQuery.extend({
4min: 1,
5fadeSpeed: 200
6}, settings);
7return this.each(function() {
8var el = $(this);
9el.hide();
10$(window).scroll(function() {
11//ie hack
12if(!jQuery.support.hrefNormalized) {
13el.css({
14'position': 'absolute',
15'bottom': $(window).scrollTop() + $(window).height() - settings.ieOffset
16});
17}
18ael = el.children('a');
19if($(window).scrollTop() >= settings.min) {
20el.fadeIn(settings.fadeSpeed);
21ael.html('<span id="topicon"></span>наверх').parent().removeClass('bottom_button').addClass('top_button');
22} else {
23ael.html('<span id="backicon"></span>назад').parent().removeClass('top_button').addClass('bottom_button');
24}
25
26});
27});
28};
29$(document).ready(function(){
30$('#top-link').css({'padding-bottom': $(window).height()});
31function mytoplink() { // функция проверки
32var h = $(window).width()/2-1000/2-100;
33// 800 - ширина сайта (обычно #wrapper)
34// 100 - ширина собственно кнопки
35if(h<0){
36$('#top-link').addClass('veryhidden');
37// если кнопка не умещается, скрываем её
38} else {
39// иначе отображаем
40$('#top-link').removeClass('veryhidden');
41$('#top-link').css({'padding-right': h+'px'});
42}
43}
44mytoplink(); // вызываем функцию проверки при загрузке страницы
45$(window).resize(function(){
46// вызываем функцию проверки при изменении размеров окна браузера
47mytoplink();
48});
49$('#top-link').topLink({min: 400,fadeSpeed: 500});
50$('#top-link').click(function(e) {
51if($(this).hasClass('bottom_button')){
52jQuery("body").scrollTo( pos + 'px', 500 );
53} else{
54pos = (window.pageYOffset !== undefined) ? window.pageYOffset : (document.documentElement || document.body.parentNode || document.body).scrollTop;
55jQuery("body,html").animate({scrollTop: 0},500);
56}
57return false;
58});
59});

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.