empty track (no knob) when board fits, add fit tolerance (v1.5.1)
This commit is contained in:
@@ -26,6 +26,10 @@
|
||||
// Keep the thumb wide enough to grab, even on a very wide board.
|
||||
var MIN_THUMB = 24;
|
||||
|
||||
// Ignore a few px of residual overflow (padding / sub-pixel rounding) so a board that visually
|
||||
// fits is treated as "no horizontal scroll" instead of showing an immovable near-full thumb.
|
||||
var FIT_TOLERANCE = 4;
|
||||
|
||||
function getContainer() {
|
||||
return document.getElementById("board-container");
|
||||
}
|
||||
@@ -74,17 +78,29 @@
|
||||
thumb.style.transform = "translateX(" + Math.round(left) + "px)";
|
||||
}
|
||||
|
||||
// Recompute thumb width/position; hide the whole bar when nothing to scroll.
|
||||
// The board needs scrolling only if its content exceeds the viewport by more than the
|
||||
// tolerance (absorbs a residual px or two so a fitting board reads as "no scroll").
|
||||
function needsScroll(m) {
|
||||
return m && m.content - m.viewport > FIT_TOLERANCE;
|
||||
}
|
||||
|
||||
// Recompute the thumb. The (light) track stays visible for a STABLE height; when the board
|
||||
// fits, just drop the knob (thumb width 0) so it reads as "nothing to scroll" without the
|
||||
// layout jump that hiding the whole bar would cause.
|
||||
function layout() {
|
||||
var m = metrics();
|
||||
|
||||
if (!m || m.content <= m.viewport || m.trackW <= 0) {
|
||||
track.style.display = "none";
|
||||
if (!m || m.trackW <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
track.style.display = "";
|
||||
|
||||
if (!needsScroll(m)) {
|
||||
thumb.style.width = "0px";
|
||||
return;
|
||||
}
|
||||
|
||||
var thumbW = Math.round(m.trackW * m.viewport / m.content);
|
||||
if (thumbW < MIN_THUMB) { thumbW = MIN_THUMB; }
|
||||
if (thumbW > m.trackW) { thumbW = m.trackW; }
|
||||
@@ -107,7 +123,7 @@
|
||||
if (dragging) { return; }
|
||||
if (e.target !== getContainer()) { return; }
|
||||
var m = metrics();
|
||||
if (!m || m.content <= m.viewport) { return; }
|
||||
if (!needsScroll(m)) { return; }
|
||||
positionThumb(m, thumb.offsetWidth);
|
||||
}, true);
|
||||
|
||||
@@ -153,7 +169,7 @@
|
||||
track.addEventListener("pointerdown", function (e) {
|
||||
if (e.target === thumb || dragging) { return; }
|
||||
var m = metrics();
|
||||
if (!m || m.content <= m.viewport) { return; }
|
||||
if (!needsScroll(m)) { return; }
|
||||
|
||||
var thumbW = thumb.offsetWidth;
|
||||
var maxThumb = m.trackW - thumbW;
|
||||
|
||||
Reference in New Issue
Block a user