SvelteKit responsive helper

王林
Release: 2024-07-18 13:13:44
Original
999 people have browsed it

SvelteKit responsive helper

Tired of writing complicated media queries ? SvelteKit windiow directives can help you simplifying them programtically. With the help of this layout component ViewoirtSettingsCatcher component and its associated store BiewportSettingsStore, they are presented in this topic.

Grabbing viewportportinner dimensions

Very simple use of svlete:window directive's bindings:

  
Copy after login

Registering inside store

$: ViewportSettingsStore.register ({ innerWidth, innerHeight })
Copy after login

the associated computation store

import { writable} from 'svelte/store' const { subscribe, update } = writable ({ innerWidth: 1600, innerHeight: 1200, ratio: 16/12, orientation: 'landscape', wide: false }) function register ({ innerWidth, innerHeight }) { const ratio = innerWidth / innerHeight const orientation = ratio >= 1 ? 'landscape' : 'portrait' const wide = (ratio > 2) || (ratio < 0.5) update ((state) => { return { innerWidth, innerHeight, orientation, ratio, wide } }) } export const ViewportSettingsStore = { subscribe, register }
Copy after login

simple usage

Just import ViewportSettingsStore in your componentr

Copy after login

Et voilà... That's done.

The above is the detailed content of SvelteKit responsive helper. For more information, please follow other related articles on the PHP Chinese website!

source:dev.to
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!