-
Notifications
You must be signed in to change notification settings - Fork 7.3k
/
fitToSection.js
61 lines (52 loc) · 1.68 KB
/
fitToSection.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import * as utils from './common/utils.js';
import { setVariableState } from './common/options.js';
import { getOptions } from './common/options.js';
import { $html } from './common/cache.js';
import { FP } from './common/constants.js';
import {
SNAPS
} from './common/selectors.js';
FP.setFitToSection = setFitToSection;
FP.fitToSection = fitToSection;
export const g_isCssSnapsSupported = (function(){
return isCssSnapsSupported();
})();
/**
* Sets fitToSection
*/
export function setFitToSection(value, type){
toggleCssSnapsWhenPossible(value);
setVariableState('fitToSection', value, type);
}
/**
* Adds or removes CSS snaps scrolling behaviour depending on the given value.
*/
export function toggleCssSnapsWhenPossible(value){
if(g_isCssSnapsSupported){
var canAddSnaps = getOptions().fitToSection && (!getOptions().autoScrolling || getOptions().scrollBar) && value;
var toggleFunction = canAddSnaps ? utils.addClass : utils.removeClass;
toggleFunction($html, SNAPS);
}
}
/**
* Checks for CSS scroll snaps support.
*/
function isCssSnapsSupported(){
var style = document.documentElement.style;
return 'scrollSnapAlign' in style ||
'webkitScrollSnapAlign' in style ||
'msScrollSnapAlign' in style;
}
/**
* Fits the site to the nearest active section
*/
export function fitToSection(){
// //checking fitToSection again in case it was set to false before the timeout delay
// if(canScroll){
// //allows to scroll to an active section and
// //if the section is already active, we prevent firing callbacks
// isResizing = true;
// scrollPage(state.activeSection);
// isResizing = false;
// }
}