Git Product home page Git Product logo

svelte-web-mobile-ui's Introduction

Svelte Web/Mobile UI Demo

This is a demonstration of a native-like sidebar flyout and mobile UI built using CSS scroll-snap. It primarily has the benefit of allowing users to use touch or trackpad gestures to open the sidebar like they would on a native app. The sidebar mechanism has zero dependencies, minimal JS presence and works on all major browsers. Although this template uses Svelte, the core principle can easily be done with vanilla HTML/CSS/JS and translates to other frameworks with miniscule impact on app size.

This template contains:

  • Trackpad and touch-compatible sidebar
  • Native-esque bottom navigation
  • svelte-spa-router
  • PWA support out-of-box (Needs icons, webmanifest, and service worker)

How does it work?

The sidebar is added globally through Svelte's layout page, with the main content placed alongside it horizontally. Both the main content and sidebar have CSS scroll-snap enabled so the user can use touch or trackpad scroll gestures to show and hide the sidebar.

The main content is set to 100% of the view width, to ensure that when the sidebar is closed, it behaves like a completely normal page. In this demo, the sidebar is set to a fixed width of 260 pixels, but could theoretically be changed to either take up the entire screen when opened (100%) or another fixed width.

Because the browser will load the layout with the sidebar open, 1-3 lines of scripting is used to instantaneously "close" the sidebar on page load. The impact of this is small compute-wise and on many browsers this will not cause layout shift.

What benefits does this method have?

  • As the sidebar uses scroll to show and hide itself, trackpad and touch gestures work out of the box.
  • JavaScript scrollBy can be used to toggle the sidebar & element scroll properties can be used to check open/closed state.
  • No external animations are needed (CSS or JS), relies on browser smooth scrolling behavior.
  • It's an ideal solution for an uncomplicated flyout sidebars for PWAs or other mobile web apps.
  • The simplicity of using scroll-snap and native browser features means this can be easily expanded upon if desired.

This demo has been tested on WebKit, Blink, and Gecko browsers but because this is an idea that I threw together really fast, it might have issues I didn't catch. You have been warned! ๐Ÿ‘ป

Try it Yourself

https://app.ivy.direct/svelte-web-mobile-ui/

svelte-web-mobile-ui's People

Contributors

dependabot[bot] avatar ivynya avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

rdelange

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.