Confinity Documentation
  • Latest Version
  • Latest Version
  • Getting Started

    • Introduction
    • Core Concepts
    • Create an Application
    • Glossary
  • Essentials

    • Authentication & SSO
    • Breaking Changes
    • Roslyn Source Analyzers
    • Changelog
    • ConfinityContent
    • ConfinitySelectable
    • Confinity Schedules
    • Data Seeding
    • Development guidelines [WIP]
    • Entity App
    • Entity Form
    • Entity Permissions
    • Frontend Configuration
    • Images
    • Known Issues
    • Localization
    • Migrations
    • Modules [WIP]
    • On-Site Editing
    • Settings
    • Cascade Delete
    • Replication
    • Infrastructure
  • Modules

    • Analytics Module
    • Assets Module
    • Blog Module
    • Cookie Consent Module
    • Forms Module
    • Friendly Captcha (Forms Module )
    • GeoIP Module
    • Htmx
    • Mail Module
    • Mailing Module
    • MediaPlayer Module
    • GoogleMyBusiness Module
    • OpenTelemetry Module
    • Pages Module [WIP]
    • Pattern Library Module
    • SIX Saferpay (worldline) Module
    • Products Module
    • Search Module
    • Wizard Module
  • Guides

    • Create a Custom Entity App Form Element
    • Date and Time
    • Entity Change Listener
    • File Upload / Temp File
    • HTTP security headers
    • conventions [WIP]
    • How to use Confinity with nginx
    • Notifications
    • Nullability
    • Rename Entity
    • Schedules
    • Useful snippets
    • Content Localization
  • Design Guidelines

    • Introduction
    • Page Components
    • Forms Module

Frontend Configuration

Scroll Position Offset

Sometimes you need to scroll programatically to a certain vertical position on the DOM. For example when a user submits a form and the validation fails, it might want to scroll to the top of the form to show the user an error message. But when you have a sticky header, it's possible that your error message is underneath the header and not visible to the user.

For this case you can check if the global variable window.__confinityScrollOffsetTop is defined and subtract it from your target scroll position. When you use a sticky header, just define this variable somewhere in your JavaScript.

Some modules, like Confinity Forms, also use this variable to scroll. So don't forget to define it, if you have a sticky header or something like that.

Example for Scrolling with Offset

let elementPos = myElement.offsetTop;
const scrollOffset = window['__confinityScrollOffsetTop'];

if (scrollOffset && !isNaN(scrollOffset)) {
    elementPos -= scrollOffset;
}
window.scrollTo({top: elementPos, behavior: 'smooth'});

Custom scrollTo function

Sometimes the scroll is made on the wrong element. This is especially a problem with multiple scrollable elements. Therefore you can overwrite the scroll method by creating a function __confinityScrollTo on the window object.

// example implementation
window.__confinityScrollTo = (targetElement) => {
    // targetElement is a HTMLElement which sould be in focus after the scroll

    let positionFromTop = element.offsetTop;
    const scrollOffset = window.__confinityScrollOffsetTop;

    if (scrollOffset && !isNaN(scrollOffset)) {
        positionFromTop -= scrollOffset;
    }

    // in this case the scroll should happen on the window
    window.scrollTo({top: positionFromTop, behavior: 'smooth'});
}

The default implementation considers the variable window.__confinityScrollOffsetTop and tries to scroll on the provided element. It goes recursively up the DOM by following it's parents and scrolls on the first scrollable element.

Prev
Entity Permissions
Next
Images