PageSourceSearch

https://finalstep.ch/wp-content/themes/lush/js/gambit-smoothscroll.js?ver=7.1.3

js finalstep.ch collected 2026-10-06 21:17:53 UTC 4,459 bytes, 170 lines download raw bytes

1/**
2 * Gambit Smooth Scroll Javascript Library
3 * Author Benjamin Intal - Gambit Technologies Inc
4 * Version 3.1
5 * License: Proprietary, Gambit Technologies Inc & Benjamin Intal
6 */
7(function() {
8
9this.GambitSmoothScroll = function( settings ){
10	if ( typeof settings === 'undefined' ) {
11		settings = {};
12	}
13	var defaults = {
14		'amount': 150,
15		'speed': 900
16	};
17	
18	for ( var key in defaults ) {
19		if ( ! settings.hasOwnProperty( key ) ) {
20			settings[ key ] = defaults[ key ];
21		}
22	}
23
24	// Disable in mobile because we don't need smooth scrolling there
25	if ( navigator.userAgent.match(/Mobi/)) {
26		return;
27	}
28	
29	this.settings = settings;
30	this.startedAsTrackpad = false;
31	this.start();
32
33};
34
35
36/**
37 * Start our plugin
38 */
39GambitSmoothScroll.prototype.start = function() {
40	document.addEventListener('DOMContentLoaded', function() {
41		window.addEventListener( 'wheel', this.overrideScroll.bind(this) );
42	}.bind(this));
43};
44
45
46/**
47 * Stops the current scroll
48 */
49GambitSmoothScroll.prototype.stop = function( isDown, timestamp ) {
50	if ( typeof this.scrollInterval !== 'undefined' ) {
51		this.startedAsTrackpad = false;
52		clearInterval( this.scrollInterval );
53		this.scrollInterval = undefined;
54	}
55};
56
57
58/**
59 * Performs the smooth page scroll
60 */
61GambitSmoothScroll.prototype.newScroll = function( isDown, timestamp ) {
62	
63	// If the scroll went the opposite way, reset the scroll as if from full stop
64	if ( isDown !== this.isDown && typeof this.isDown !== 'undefined' ) {
65		this.stop();
66	}
67	this.isDown = isDown;
68	
69	// If called to scroll from a full stop, create our scroller loop
70	if ( typeof this.scrollInterval === 'undefined' ) {
71		
72		this.startingSpeed = this.settings.amount;
73		this.scrollInterval = setInterval( function() {
74			
75			// Perform the scroll
76			var scrollBy = ( this.isDown ? 1 : -1 ) * this.startingSpeed / 15;
77
78			//window.scrollBy( 0, scrollBy );
79			document.getElementById("pusher").scrollTop += scrollBy;
80
81			// Stop the scroller when the scroll becomes too small
82			this.startingSpeed *= 1 - ( 900 / this.settings.speed ) / 10; // 0.9;
83			if ( Math.abs( scrollBy ) < 1 ) {
84				this.stop();
85			}
86
87		}.bind(this), 16.666666667 ); // 60fps
88		
89	// If called while the page is still scrolling, add more momentum to the current scroll
90	} else {
91		// Base the momentum multiplier on the delta time to avoid super fast scrolls
92		var multiplier = 1 + ( timestamp - this.prevTimestamp ) / 40 * 0.7;
93		
94		// Limit the amount
95		this.startingSpeed = Math.max( this.startingSpeed * multiplier, this.settings.amount );
96		this.startingSpeed = Math.min( this.startingSpeed, 300 );
97	}
98
99	this.prevTimestamp = timestamp;
100};
101
102
103/**
104 * Stops the default scroll behavior and does our own thing
105 */
106GambitSmoothScroll.prototype.overrideScroll = function(e) {
107
108
109	if(!jQuery('.side-menu').hasClass('open')) {
110	
111	// Normalize wheel delta scroll
112	var delta = e.wheelDelta ? -e.wheelDelta / 120 : (e.detail || e.deltaY) / 3;
113	
114	/**
115	 * Basically, when we check the delta variable, trackpads give out a value of < 1 && < -1
116	 * mouse wheel scrolls give out a value >= 1 || <= -1
117	 * We can use this to turn OFF smooth scrolling for trackpads.
118	 *
119	 * IMPORTANT: Firefox in Mac somehow handles things differently.
120	 * the skipCheck variable handles things for FF in Macs
121	 */
122	
123	// Special for Firefox-Mac
124	var skipCheck = false;
125	if ( typeof window.mozInnerScreenX !== 'undefined' ) {
126		if ( navigator.platform.indexOf( 'Mac' ) !== -1 ) {
127			this.startedAsTrackpad = false;
128			skipCheck = true;
129			if ( e.deltaY === parseInt( e.deltaY, 10 ) ) {
130				this.startedAsTrackpad = true;
131				return;
132			}
133		}
134	}
135
136	if ( typeof this.trackpadTimeout !== 'undefined' ) {
137		clearTimeout( this.trackpadTimeout );
138		this.trackpadTimeout = undefined;
139	}
140	
141	// If delta is less than 1, assume that we are using a trackpad and do the normal behavior
142	if ( ( Math.abs( delta ) < 1 || this.startedAsTrackpad ) && ! skipCheck ) {
143		
144		this.trackpadTimeout = setTimeout( function() {
145			this.startedAsTrackpad = false;
146			this.trackpadTimeout = undefined;
147		}.bind(this), 200 );
148		
149		this.startedAsTrackpad = true;
150		return true;
151	}
152	
153	// If the code reaches here, then scrolling will be smoothened
154
155	// Disable normal scrolling
156	e = e || window.event;
157	if ( e.preventDefault ) {
158		e.preventDefault();
159	}
160	e.returnValue = false;  
161	
162	// Perform our own scrolling
163	this.newScroll( delta > 0, e.timeStamp );
164};
165
166}// end : if(!jQuery('.side-menu').hasClass('open'))
167
168}());
169
170new GambitSmoothScroll();

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.