PageSourceSearch

https://center.piccoloschool.ru/templates/piccollo/js/jquery.hidescroll.js

js piccoloschool.ru collected 2026-10-07 14:22:24 UTC 2,423 bytes, 129 lines download raw bytes

1;(function($, window, document, undefined) {
2
3	var name = 'hidescroll',
4		defaults = {
5			offset: 0,
6			interval: 250,
7			stickClass: 'stick',
8			visibleClass: 'visible',
9			hiddenClass: 'hidden'
10		};
11
12	function Hidescroll(element, options) {
13
14		this.options = $.extend({}, defaults, options);
15		this.navbar = element;
16
17		this.init();
18
19	}
20
21	/**
22	 * Calculate actual scroll position and direction
23	 * @param  {Object} event
24	 */
25	Hidescroll.prototype.calculate = function(event) {
26
27		var scroll = $(document).scrollTop();
28
29		if (scroll > this.scroll) this.direction = -1;
30		else this.direction = 1;
31
32		this.action = true;
33		this.scroll = scroll;
34
35	};
36
37	/**
38	 * Bind navbar methods
39	 */
40	Hidescroll.prototype.bindings = function() {
41
42		var o = this.options;
43
44		this.navbar.bind({
45
46			normalPosition: function () {
47				$(this).removeClass(
48					o.stickClass + ' ' + o.visibleClass + ' ' + o.hiddenClass
49				);
50			},
51			stickHiddenPosition: function () {
52				$(this).addClass(
53					o.stickClass  + ' ' + o.hiddenClass
54				).removeClass(o.visibleClass);
55			},
56			stickVisiblePosition: function () {
57				$(this).addClass(o.visibleClass).removeClass(o.hiddenClass);
58			},
59
60		});
61
62	};
63
64	/**
65	 * Handle navbar state
66	 */
67	Hidescroll.prototype.handle = function() {
68
69		if(this.scroll === 0)
70			return this.navbar.trigger('normalPosition');
71
72		if (this.direction < 0 && this.scroll > this.options.offset)
73			return this.navbar.trigger('stickHiddenPosition');
74
75		else
76			return this.navbar.trigger('stickVisiblePosition');
77
78	};
79
80	/**
81	 * Events bindings
82	 */
83	Hidescroll.prototype.events = function () {
84
85		$(window).on('scroll', $.proxy(this.calculate, this));
86
87	};
88
89	/**
90	 * [status description]
91	 * @return {[type]} [description]
92	 */
93	Hidescroll.prototype.status = function() {
94
95		var that = this;
96
97		setInterval(function() {
98			if (that.action) {
99				that.handle();
100				that.action = false;
101			}
102		}, this.options.interval);
103
104	};
105
106	Hidescroll.prototype.init = function () {
107
108		this.scroll = 0;
109		this.direction = 0;
110		this.options.offset = (this.options.offset === 0) ? this.navbar.outerHeight() : this.options.offset;
111		this.action = true;
112
113		this.bindings();
114		this.events();
115		this.status();
116
117	};
118
119	$.fn[name] = function(options) {
120		return this.each(function () {
121			if (!$.data(this, 'api_' + name)) {
122				$.data(this, 'api_' + name,
123					new Hidescroll($(this), options)
124				);
125			}
126		});
127	};
128
129})(jQuery, window, document);

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.