tree scroll snapping

This commit is contained in:
ed 2021-04-10 19:30:30 +02:00
parent 8e128d917e
commit 59ebc795e7
2 changed files with 46 additions and 8 deletions

View file

@ -495,7 +495,7 @@ input[type="checkbox"]:checked+label {
} }
#tree { #tree {
display: none; display: none;
position: fixed; position: absolute;
left: 0; left: 0;
bottom: 0; bottom: 0;
top: 7em; top: 7em;

View file

@ -872,12 +872,16 @@ document.onkeydown = function (e) {
var treectl = (function () { var treectl = (function () {
var treectl = { var treectl = {
"hidden": false "hidden": false
}; },
var dyn = bcfg_get('dyntree', true); entreed = false,
var treesz = icfg_get('treesz', 16); fixedpos = false,
prev_atop = null,
prev_winh = null,
dyn = bcfg_get('dyntree', true),
treesz = icfg_get('treesz', 16);
treesz = Math.min(Math.max(treesz, 4), 50); treesz = Math.min(Math.max(treesz, 4), 50);
console.log('treesz [' + treesz + ']'); console.log('treesz [' + treesz + ']');
var entreed = false;
function entree(e) { function entree(e) {
ev(e); ev(e);
@ -909,13 +913,47 @@ var treectl = (function () {
if (!entreed || treectl.hidden) if (!entreed || treectl.hidden)
return; return;
var top = ebi('wrap').getBoundingClientRect().top; var tree = ebi('tree'),
ebi('tree').style.top = Math.max(0, parseInt(top)) + 'px'; wrap = ebi('wrap'),
atop = wrap.getBoundingClientRect().top,
winh = window.innerHeight;
if (atop === prev_atop && winh === prev_winh)
return;
prev_atop = atop;
prev_winh = winh;
if (fixedpos && atop >= 0) {
tree.style.position = 'absolute';
tree.style.bottom = '';
fixedpos = false;
}
else if (!fixedpos && atop < 0) {
tree.style.position = 'fixed';
tree.style.height = 'auto';
fixedpos = true;
}
if (fixedpos) {
tree.style.top = Math.max(0, parseInt(atop)) + 'px';
}
else {
var wraph = parseInt(getComputedStyle(ebi('wrap').offsetParent).height),
top = Math.max(0, parseInt(wrap.offsetTop)),
treeh = winh - atop;
if (treeh < 10)
return;
tree.style.top = top + 'px';
tree.style.height = treeh + 'px';
}
} }
function periodic() { function periodic() {
onscroll(); onscroll();
setTimeout(periodic, document.visibilityState ? 200 : 5000); setTimeout(periodic, document.visibilityState ? 100 : 5000);
} }
periodic(); periodic();