Git Product home page Git Product logo

pleaserotate.js's Introduction

pleaserotate.js

A simple way to force mobile users to view your site in portrait or landscape mode. Include this js file and it will replace your site with a friendly message until the users' device is in the proper orientation.

Example

View it in action over here (mobile device required to see it).

Basic Usage

Just include the script file anywhere in your doc:

<script src="pleaserotate.js"></script>

Style using CSS. Configure by creating a window.PleaseRotateOptions object before you include the script.

<style>
    /* style the elements with CSS */
    #pleaserotate-graphic{
        fill: #fff;
    }

    #pleaserotate-backdrop {
        color: #fff;
        background-color: #000;
    }
</style>

<script>
    /* you can pass in options here */
    PleaseRotateOptions = {
        forcePortrait: true // if you would prefer to force portrait mode
    };
</script>
<script src="pleaserotate.js"></script>

Using AMD or CommonJS

This supports AMD and CommonJS. Require pleaserotate.js and call PleaseRotate.start(options) to use.

Options

The current default options are:

var PleaseRotateOptions = {
    startOnPageLoad: true,
    onHide: function(){},
    onShow: function(){},
    forcePortrait: false,
    message: "Please Rotate Your Device",
    subMessage: "(or click to continue)",
    allowClickBypass: true,
    onlyMobile: true,
    zIndex: 1000,
    iconNode: null
};

Note Regarding Startup

Depending on where you including the javascript file, other parts of your site could render before pleaserotate.js has a chance to block them out. To help you work around that, pleaserotate.js attaches classes to the <html> element while running. Look for pleaserotate-showing and pleaserotate-hiding classes, which indicate that pleaserotate.js has finished loading and if it is currently showing the "Please Rotate" message or not. You can use CSS to hide parts of your page until those classes show up.

pleaserotate.js's People

Contributors

arscan avatar micpob 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.