Skip to content

An Alpine JS Screen Plugin lets you programmatically monitor changes to the size of the screen

Notifications You must be signed in to change notification settings

victoryoalli/alpinejs-screen

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Alpine.js plugin Screen

GitHub release (latest by date)

An Alpine JS Screen Plugin lets you programmatically monitor changes to the size of the screen

Instalation

Via script include

<script src="/js/screen.min.js" defer></script>
<script src="/js/alpine.js" defer></script>

Via CDN

<!-- Alpine Plugins -->
<script src="https://unpkg.com/@victoryoalli/[email protected]/dist/screen.min.js" defer></script>
<!-- Alpine Core -->
<script defer src="https://unpkg.com/[email protected]/dist/cdn.min.js"></script>

Via NPM

npm i @victoryoalli/alpinejs-screen
import Alpine from 'alpinejs'

import screen from '@victoryoalli/alpinejs-screen'
Alpine.plugin(screen)

window.Alpine = Alpine
window.Alpine.start()

x-screen

Directive

    <div x-data x-screen="alert('screen resized')"></div>

$width and $height

Magic helpers

  • $width This magic helper will return window.outerWidth

  • $height This magic helper will return window.outerHeight

Example

Using $width magic helper

<html>
    <script src="/js/screen.min.js" defer></script>
    <script src="/js/alpine.js" defer></script>
    <div x-screen="isMobile = ($width<1024)">
        <span x-show="isMobile"> MOBILE </span>
    </div>
</html>

About

An Alpine JS Screen Plugin lets you programmatically monitor changes to the size of the screen

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published