Giter Site home page Giter Site logo

casumo-archive / scream Goto Github PK

View Code? Open in Web Editor NEW

This project forked from gajus/scream

0.0 4.0 0.0 1.6 MB

Dynamic viewport management for mobile. Manage viewport in different states of device orientation. Scale document to fit viewport. Calculate the dimensions of the "minimal" iOS 8 view relative to your viewport width.

License: Other

JavaScript 79.90% HTML 11.62% CSS 8.48%

scream's Introduction

Scream

NPM version

Dynamic viewport management for mobile.

  • Manage viewport in different states of device orientation.
  • Scale document to fit viewport.
  • Calculate the dimensions of the "minimal" iOS 8 view relative to your viewport width.

Demonstration using iOS simulator

Contents

Managing the Viewport

Configure dimensions of the viewport at the time of the initialization:

import Scream from 'scream';

const scream = Scream({
    width: {
        portrait: 320,
        landscape: 640
    }
});

Scream generates the viewport meta tag to reflect the present orientation and in response to the orientationchangeend event.

<meta name="viewport" content="width={width},initial-scale={scale},minimum-scale={scale},maximum-scale={scale},user-scale=0">
  • {width} the width set in the configuration for the current orientation.
  • {scale} calculated scale needed to fit the document in the screen.

Configuration

Name Description Default
width.portrait Viewport width in the portrait orientation. screen.width (device-width)
width.landscape Viewport width in the landscape orientation. screen.width (device-width)

Events

Orientation Change

The orientationchangeend event is fired when the orientation of the device has changed and the associated rotation animation has been complete.

โ€“ย https://github.com/gajus/orientationchangeend

This is proxy for your convenience to perform operations that must follow the change of the device orientation and in the context of updated viewport tag. This is required when determining the view state.

scream.on('orientationchangeend', () => {
    // Invoked after the orientation change and the associated animation (iOS) has been completed.
});

View Change

Invoked on page load and when view changes.

scream.on('viewchange', (e) => {
    // @var {String} 'full', 'minimal'
    e.viewName;
});

Unregister the event

The on method returns a listener object that you can use to unregister your event handler calling the method off.

const listener = scream.on('viewchange', (e) => { /* your code */ });

// to unregister:

scream.off(listener);

Screen

/**
 * @return {String} portrait|landscape
 */
scream.getOrientation();

/**
 * Screen width relative to the device orientation.
 *
 * @return {Number}
 */
scream.getScreenWidth();

/**
 * Screen width relative to the device orientation.
 *
 * @return {Number}
 */
scream.getScreenHeight();

Viewport

/**
 * Viewport width relative to the device orientation.
 *
 * @return {Number}
 */
scream.getViewportWidth();

/**
 * Viewport height relative to the device orientation and to scale with the viewport width.
 *
 * @return {Number}
 */
scream.getViewportHeight();

/**
 * The ratio between screen width and viewport width.
 *
 * @return {Number}
 */
scream.getScale();

Minimal View

This functionality is iOS 8 specific. It has been developed as part of Brim to bring back the minimal-ui.

/**
 * Returns dimensions of the usable viewport in the minimal view relative to the current viewport width and orientation.
 *
 * @return {Object} dimensions
 * @return {Number} dimensions.width
 * @return {Number} dimensions.height
 */
scream.getMinimalViewSize();

/**
 * Returns true if screen is in "minimal" UI.
 *
 * iOS 8 has removed the minimal-ui viewport property.
 * Nevertheless, user can enter minimal-ui using touch-drag-down gesture.
 * This method is used to detect if user is in minimal-ui view.
 *
 * In case of orientation change, the state of the view can be accurately
 * determined only after orientationchangeend event.
 *
 * @return {Boolean}
 */
scream.isMinimalView();

Download

Using NPM:

npm install scream

scream's People

Contributors

bertyhell avatar craigbeswetherick avatar francoagusto avatar gajus avatar joe-palmer avatar marcoacierno avatar

Watchers

 avatar  avatar  avatar  avatar

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.