2.1.2 • Published 6 years ago

mobile-orientation v2.1.2

Weekly downloads
174
License
ISC
Repository
github
Last release
6 years ago

Mobile-Orientation

Detect Mobile Portrait/Landscape on resize. See demo.

Browser compatibility

See MDN.

Install

npm install --save mobile-orientation

Usage

import { MobileOrientation } from 'mobile-orientation'

const orientation = new MobileOrientation()

console.log(orientation.state) // 'portrait'

orientation.on('resize', state => console.log(state)) // portrait or landscape
orientation.on('portrait', state => console.log(state)) // portrait
orientation.on('landscape', state => console.log(state)) // landscape

Alternatively, the state can be utilized within a computed property, a la Vue.js Computed Property.

// Vue Component
export default {
    data() {
        return {
            orientation: new MobileOrientation()
        }
    },
    computed: {
        isPortrait() {
            return this.orientation.isPortrait
        },
        isLandscape() {
            return this.orientation.isLandscape
        }
    }
}

Options

debounceTime

  • Type: Number
  • Default: 50
  • Format: Milliseconds
  • Description: Time to wait before invoking detection.

withTouch

  • Type: Boolean
  • Default: false
  • Description: Include touch-device when testing mobile.

portraitMediaQuery

See MDN for media queries syntax.

  • Type: String
  • Default: screen and (max-device-aspect-ratio: 1/1)
  • Format: CSS Media Query
  • Description: CSS Media Query to test against portrait.

landscapeMediaQuery

See MDN for media queries syntax.

  • Type: String
  • Default: all
  • Format: CSS Media Query
  • Description: CSS Media Query to test against landscape.
2.1.2

6 years ago

2.1.1

6 years ago

2.1.0

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.2.6

6 years ago

1.2.5

6 years ago

1.2.4

6 years ago

1.2.3

6 years ago

1.2.2

6 years ago

1.2.1

6 years ago

1.2.0

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago