-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathscroll.js
More file actions
87 lines (84 loc) · 2.45 KB
/
scroll.js
File metadata and controls
87 lines (84 loc) · 2.45 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
settings.register({
name: 'Disable Deck Scroll',
key: 'underscript.disable.deckScroll',
refresh: () => onPage('Decks'),
});
onPage('Decks', function () {
debug('Deckscroll');
if (settings.value('underscript.disable.deckScroll')) return;
eventManager.on(':load', () => {
debug('load');
debug($('#deckCards').offset())
const cardList = $('#yourCardList');
cardList.css({
'position': 'absolute',
'max-width': '180px',
});
let oOffset = cardList.offset().top - 5;
let oOffsetDeck;
function reset() {
cardList.css({
position: 'absolute',
top: '',
});
$('#deckCards').css({
position: '',
width: '',
top: '',
});
}
function deck() {
return $(`#deckCards`);
}
function resize() {
if (!oOffsetDeck) {
// Somehow the page isn't loaded completely at load time (very misleading)
oOffsetDeck = deck().offset().top - 5;
}
// Calculated here because cardList can change height
const footerHeight = $('body > footer').height();
const maxHeight = 5 + cardList.height() + footerHeight;
//debug(`oOffset:${oOffset}; oOffsetDeck:${oOffsetDeck}; pageOffset:${window.pageYOffset}; maxHeight:${maxHeight}`);
if (window.innerHeight < maxHeight) {
debug(`${window.innerHeight}, ${maxHeight}, ${window.pageYOffset}, ${oOffsetDeck}, ${deck().height()}`);
// Lock to the deck offset instead
debug('small screen');
if (window.pageYOffset > oOffsetDeck && window.innerHeight > deck().height() + footerHeight) {
debug('fixed oOffsetDeck');
$('#deckCards').css({
position: 'fixed',
width: '180px',
top: 5,
});
} else {
$('#deckCards').css({
position: '',
width: '',
top: '',
});
}
cardList.css({
position: '',
top: '',
});
} else if (window.pageYOffset > oOffset) {
debug('fixed oOffset');
cardList.css({
position: 'fixed',
top: 5,
});
} else {
debug('default');
reset();
}
}
eventManager.on('addCardtoDeck', resize);
$(window).on('resize.script', () => {
oOffset = cardList.offset().top - 5;
oOffsetDeck = deck().offset().top - 5;
reset();
resize();
});
$(window).on('scroll.script', resize);
});
});