-
Notifications
You must be signed in to change notification settings - Fork 7.3k
/
autoScrolling.js
74 lines (62 loc) · 2.16 KB
/
autoScrolling.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
62
63
64
65
66
67
68
69
70
71
72
73
74
import * as utils from './common/utils.js';
import { silentScroll } from './common/silentScroll.js';
import { getScrollSettings } from './common/utilsFP.js';
import {
setVariableState,
getOptions,
getOriginals,
getContainer
} from './common/options.js';
import { getState } from './common/state.js';
import { FP } from './common/constants.js';
import { $body, $htmlBody } from './common/cache.js';
import { setRecordHistory } from './anchors/setRecordHistory.js';
FP.setAutoScrolling = setAutoScrolling;
FP.test.setAutoScrolling = setAutoScrolling;
/**
* Sets the autoScroll option.
* It changes the scroll bar visibility and the history of the site as a result.
*/
export function setAutoScrolling(value, type){
//removing the transformation
if(!value){
silentScroll(0);
}
setVariableState('autoScrolling', value, type);
var element = getState().activeSection.item;
if(getOptions().autoScrolling && !getOptions().scrollBar){
utils.css($htmlBody, {
'overflow': 'hidden',
'height': '100%'
});
utils.removeClass($body, 'fp-scrollable');
setRecordHistory(getOriginals().recordHistory, 'internal');
//for IE touch devices
utils.css(getContainer(), {
'-ms-touch-action': 'none',
'touch-action': 'none'
});
if(element != null){
//moving the container up
silentScroll(element.offsetTop);
}
}else{
utils.css($htmlBody, {
'overflow' : 'visible',
'height' : 'initial'
});
utils.addClass($body, 'fp-scrollable');
var recordHistory = !getOptions().autoScrolling ? false : getOriginals().recordHistory;
setRecordHistory(recordHistory, 'internal');
//for IE touch devices
utils.css(getContainer(), {
'-ms-touch-action': '',
'touch-action': ''
});
//scrolling the page to the section with no animation
if (element != null) {
var scrollSettings = getScrollSettings(element.offsetTop);
scrollSettings.element.scrollTo(0, scrollSettings.options);
}
}
}