Giter VIP home page Giter VIP logo

setviewport's Introduction

#setviewport

A small script (JS) to insert the viewport meta tag into an HTML document's head at a specified width. Now with example app.js script to clarify use of the global vars.

Basic Use:

Insert the viewport.js code in the document head, preferably at the earliest point after the opening <head> tag. Find the window.triggerWidth; global and set it to the width (in pixels) that you want the viewport tag to render.

See live example This is a same code as example.html

600 (pixels) is the default.

The default viewport metatag settings are: width=device-width initial-scale=1

Note that it also has orientation detection and substitution, so that rotated devices will use the widest aspect.

Available Vars:

The function mobileWidth(); adds a variable to the global window object:

viewportWidth - window or screen (whichever is smaller), based on device orientation.

In addition, we set the triggerWidth - the width you set when calling mobileWidth(), also used to trigger addViewport()

The purpose of making these available globally is to allow for additional JS/jQuery usage, for example, in your main JS file, you could have the following:

var isMobile = false;
if ( viewportWidth <= triggerWidth ) {
    isMobile = true;
}

See extended example in app.js

License and Credits

© 2013,2014 Komejo. Created by Joe Komenda.

setviewport.js is released under the MIT license.

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.