cinera_pre.js: Add sticky-awareness to auto-scroll

This lets the grid view auto-scroll out from under the control bar.
This commit is contained in:
Matt Mascarenhas 2021-02-07 01:53:05 +00:00
parent 7e80017434
commit 4ba03f9338
3 changed files with 11 additions and 9 deletions

View File

@ -23,7 +23,7 @@ typedef struct
version CINERA_APP_VERSION = {
.Major = 0,
.Minor = 8,
.Patch = 4
.Patch = 5
};
#include <stdarg.h> // NOTE(matt): varargs

View File

@ -268,21 +268,23 @@ var ScrollTicking = false;
var ScrollerFunction;
var ScrollCondition;
function ScrollTo(Element, ScrollPos) {
function ScrollTo(Element, ScrollPos, StickyObscuringElement) {
var BoundingRect = Element.getBoundingClientRect();
var Height = BoundingRect.height;
var PercentageOfInView = 89;
var GatherableHeight = Height * (1 - PercentageOfInView / 100);
var ScrollY = BoundingRect.top;
var YOffsetFromPage = getElementYOffsetFromPage(Element);
var DesiredScroll = null;
if(ScrollY < 0)
var DesiredScroll = null;
var Ceiling = StickyObscuringElement ? StickyObscuringElement.offsetHeight : 0;
if(ScrollY < Ceiling)
{
ScrollY = ~ScrollY;
if(ScrollY < 0) { ScrollY = -ScrollY; }
if(ScrollY <= GatherableHeight)
{
DesiredScroll = YOffsetFromPage;
DesiredScroll = YOffsetFromPage - Ceiling;
}
}
else
@ -304,7 +306,7 @@ function ScrollTo(Element, ScrollPos) {
}
function
InitScrollEventListener(Element)
InitScrollEventListener(Element, StickyObscuringElement)
{
window.addEventListener('scroll', function() {
if(ScrollCondition == undefined || ScrollCondition == true)
@ -314,7 +316,7 @@ InitScrollEventListener(Element)
if (!ScrollTicking) {
window.requestAnimationFrame(function() {
clearTimeout(ScrollerFunction);
ScrollerFunction = setTimeout(ScrollTo, 2000, Element, LastScrollYPos);
ScrollerFunction = setTimeout(ScrollTo, 2000, Element, LastScrollYPos, StickyObscuringElement);
ScrollTicking = false;
});

View File

@ -55,7 +55,7 @@ BindGridKeys(Nav.GridSize);
BindControls();
InitResizeEventListener();
InitOrientationChangeListener();
InitScrollEventListener(Nav.Grid);
InitScrollEventListener(Nav.GridContainer, Nav.Controls.Header);
//
////