Fullscreen API. Quick Guides for Masterminds. J.D Gauchat Cover Illustration by Patrice Garden

Similar documents
App Development. Quick Guides for Masterminds. J.D Gauchat Cover Illustration by Patrice Garden

Frontend guide. Everything you need to know about HTML, CSS, JavaScript and DOM. Dejan V Čančarević

HTML5 and CSS3: New Markup & Styles for the Emerging Web. Jason Clark Head of Digital Access & Web Services Montana State University Library

Stamp Builder. Documentation. v1.0.0

HTML5 MOCK TEST HTML5 MOCK TEST I

UNIT 3 SECTION 1 Answer the following questions Q.1: What is an editor? editor editor Q.2: What do you understand by a web browser?

Web Site Design and Development. CS 0134 Fall 2018 Tues and Thurs 1:00 2:15PM

HTML5. for Masterminds. (1st Edition) J.D Gauchat

Javascript Performance in the Browser. Charlie Fiskeaux II User Interface Engineer

UPK and UPK Professional Technical Specifications

HTML5 and Mobile: New Markup & Styles for the Mobile Web. Jason Clark Head of Digital Access & Web Services Montana State University Libraries

WHAT S NEW IN ORACLE USER PRODUCTIVITY KIT PROFESSIONAL

WHAT S NEW IN ORACLE USER PRODUCTIVITY KIT

UPK and UPK Professional Technical Specifications

The course also includes an overview of some of the most popular frameworks that you will most likely encounter in your real work environments.

UPK Professional Technical Specifications. Version

16. HTML5, HTML Graphics, & HTML Media 웹프로그래밍 2016 년 1 학기 충남대학교컴퓨터공학과

VISUAL QUICKPRO GUIDE

WHAT S NEW IN ORACLE USER PRODUCTIVITY KIT PROFESSIONAL

Create Institutional Membership

HTML. Mohammed Alhessi M.Sc. Geomatics Engineering. Internet GIS Technologies كلية اآلداب - قسم الجغرافيا نظم المعلومات الجغرافية

WebKit ; FOR : DUMMIES. by Chris Minnick WILEY. John Wiley & Sons, Inc.

Lecture Topic Projects

A network is a group of two or more computers that are connected to share resources and information.

Web Programming and Design. MPT Senior Cycle Tutor: Tamara Week 1

Lewis Weaver. Nell Waliczek. Software Engineering Lead. Program github.

VectorDraw web Library

I Can t Believe It s Not

A340 Laboratory Session #5

INTRODUCTION TO HTML5! HTML5 Page Structure!

Internet: An international network of connected computers. The purpose of connecting computers together, of course, is to share information.

TIBCO NimbusTM SharePoint Customization Guide. Software Release March 2015

User and Reference Manual

USER GUIDE PowerPhoto CRM

JavaScript: Introduction, Types

Anatomy of an HTML document

All India Council For Research & Training

1. Setup a root folder for the website 2. Create a wireframe 3. Add content 4. Create hyperlinks between pages and to external websites

GfK Digital Trends App. Installation Guide & User Manual for Microsoft Internet Explorer users

Mustang Wiring & Vacuum Diagrams

Contents. 1. Using Cherry 1.1 Getting started 1.2 Logging in

TIBCO Nimbus Control. SharePoint Customization Guide. Software Release July 2013

VTEM SLIDES INSTRUCTION MANUAL COPYRIGHT DISCLAIMER. Instruction Manual FOR INFO, UPDATES, REQUESTS & CONTACT

AvePoint Permissions Manager

Web Programming HTML CSS JavaScript Step by step Exercises Hans-Petter Halvorsen

NEW WEBMASTER HTML & CSS FOR BEGINNERS COURSE SYNOPSIS

Client Side Scripting. The Bookshop

Web Programming and Design. MPT Junior Cycle Tutor: Tamara Demonstrators: Aaron, Marion, Hugh

About 1. Chapter 1: Getting started with ckeditor 2. Remarks 2. Versions 2. Examples 3. Getting Started 3. Explanation of code 4

2D Game design Intro to Html 5

Software Integration Guide

XML Primer Plus By Nicholas Chase

Mining the Rendering Power in Web Browsers. Jianxia Xue Jan. 28, 2014

B r o w s e r s u p p o r t

Installation Guide. Copyright 2011 Bitdefender

Lesson 5: Multimedia on the Web

Create Individual Membership. This step-by-step guide takes you through the process to create an Individual Membership.

Wowza Cloud Preview. Quick Start Guide. Copyright by Wowza Media Systems, LLC. All rights reserved.

Introduction to JavaScript p. 1 JavaScript Myths p. 2 Versions of JavaScript p. 2 Client-Side JavaScript p. 3 JavaScript in Other Contexts p.

NAVIGATION INSTRUCTIONS

IBM Rational Rhapsody Gateway Add On. Tagger Manual

Axon Capture for ios App Guide. Axon Capture Release: 3.x Release Date: February 2016 Document Revision: A

PLAYER DEVELOPER GUIDE

Oracle WebCenter Portal 11g Developer Workshop

RAI TRADE TAPELESS RECEPTION

Oracle Learn Cloud. What s New in Release 15B.1

CREATE SASSY WEB PARTS. Developer Guide to SASS usage in SPFx

Working with Screencast-O-Matic (SOM)

Displaying ndtv Graphics in Spotfire using TERR and JSViz

Introduction to HTML5

CSCI 1100L: Topics in Computing Spring 2018 Web Page Project 50 points

Web API for Vehicle Data RI

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer ASP.NET WP

Beginning HTML. The Nuts and Bolts of building Web pages.

Manual Html A Href Javascript Window Open In New

The course is supplemented by numerous hands-on labs that help attendees reinforce their theoretical knowledge of the learned material.

KMC Converge GFX User Guide

CMS 101. For questions or issues: go.pacific.edu/webrequest

COURSE 20480B: PROGRAMMING IN HTML5 WITH JAVASCRIPT AND CSS3

Aras Innovator 11. Client Settings for Firefox on Windows

In-ADS User Guide. Estonian Land Board Versioon 1.9.1

Varargs Training & Software Development Centre Private Limited, Module: HTML5, CSS3 & JavaScript

TIBCO Nimbus. SharePoint Customization Guide. Software Release November 2017

Oracle Enterprise Performance Reporting Cloud. What s New in June 2017 Update (17.06)

Structural Engineering Library

Programming in HTML5 with JavaScript and CSS3

What is XHTML? XHTML is the language used to create and organize a web page:

Copyright 2018 MakeUseOf. All Rights Reserved.

Search Engine Optimization and Placement:

Tutorial 5 Working with Tables and Columns. HTML and CSS 6 TH EDITION

Session 3: JavaScript - Structured Programming

WCO CLiKC! Connection and Access Guide for Users

Creating Content in a Course Area

Designing the Home Page and Creating Additional Pages

Virto Html5 Bulk File Upload for Microsoft SharePoint Release User and Installation Guide

File Share Navigator Online. Release Notes

Chapter 1 Getting Started with HTML 5 1. Chapter 2 Introduction to New Elements in HTML 5 21

VISUAL QUICKPRO GUIDE

Variables and Typing

Rapt Media Player API v2

Transcription:

Fullscreen API Quick Guides for Masterminds J.D Gauchat www.jdgauchat.com Cover Illustration by Patrice Garden www.smartcreativz.com

Quick Guides for Masterminds Copyright 2018 by John D Gauchat All Rights Reserved No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage or retrieval system without the prior written permission of the copyright owner. Companies, services, or product names used in this ebook are for identification purposes only. All trademarks and registered trademarks are the property of their respective owners. The content of this guide is a collection of excerpts from the book HTML5 for Masterminds. For more information, visit www.formasterminds.com. The information in this ebook is distributed on an "as is" basis, without warranty. Although every precaution has been taken in the preparation of this work, neither the author nor the publisher shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the information contained in this work. The source code for this ebook is available at www.formasterminds.com Copyright Registration Number: 1140725 1 st Edition 2018

What is Inside This guide will teach you how to use the Fullscreen API to take your website or web application full screen. After reading this guide, you will know how to take an element full screen, how to detect if an element is full screen, and how to style the elements when they are in full screen mode. About this Guide This guide is a collection of excerpts from the book HTML5 for Masterminds. The information included in this guide will help you understand a particular aspect of web development, but it will not teach you everything you need to know to develop a website or a web application. If you need a complete course on web development, read our book HTML5 for Masterminds. For more information, visit our website at www.formasterminds.com. What Do You Need This guide assumes that you have a basic knowledge of HTML, CSS and JavaScript, and you know how to create files and upload them to a server. If you don't know how to program in HTML, CSS or JavaScript, you can download our guides Introduction to HTML, Introduction to CSS, and Introduction to JavaScript. For a complete course on web development, read our book HTML5 for Masterminds. IMPORTANT: We recommend you to execute the examples in this guide with the latest versions of Google Chrome and Mozilla Firefox (www.google.com/chrome and www.mozilla.com). You can also check the state of the current implementations at www.caniuse.com. To find examples, resources, links and videos, visit our website at www.formasterminds.com. The Basics: To create the files for the examples of this guide, you can use a text editor (Notepad or Text Edit), or a professional editor like Atom (www.atom.io). If you do not have a server to test the files, you can install a server in your computer with a package like MAMP (www.mamp.info). For more information, read our free guide Web Development.

Recommendations Introduction to JavaScript Quick Guides for Masterminds This guide will teach you how to program with JavaScript. After reading this guide, you will know how to create a program in JavaScript, how to define functions and objects, and how to read and modify an HTML document dynamically. More Information Introduction to HTML Quick Guides for Masterminds This guide will teach you how to create your website's documents with HTML. After reading this guide, you will know how to work with HTML elements, how to define a document's structure, and how to organize its content. More Information Canvas API Quick Guides for Masterminds This guide will teach you how to create graphic applications for your webiste with the Canvas API. After reading this guide, you will know how to create graphics for the web, how to manipulate images, and how to generate animations and small video games. More Information More Guides Available at www.formasterminds.com

Table of Contents FULLSCREEN API Modern Applications Full Screen Full Screen Styles QUICK REFERENCE Properties Methods Events

Fullscreen API Modern Applications The Web is a multipurpose and multimedia platform where everything is possible. With so many interesting new applications, the word navigation has almost lost significance. The browser's interface is not only unnecessary but sometimes may get in the way. For this reason, browsers include the Fullscreen API. Full Screen The Fullscreen API lets us expand any element in the document to occupy the entire screen. As a result, the browser s interface is hidden in the background, allowing the user to focus his or her attention on our video, picture, application or video game. The API provides a few properties, methods and events to take an element to full screen mode, exit the full screen mode, and retrieve some information from the element and the document that are participating in the process. fullscreenelement This property returns a reference to the element that is in full screen mode. If no element is full screen, the property returns null. fullscreenenabled This Boolean property returns true when the document is able to go full screen or false otherwise. requestfullscreen() This method is available for every element in the document. It activates full screen mode for the element. exitfullscreen() This method is available for the document. If an element is in full screen mode, the method cancels the mode and returns the focus back to the browser window. The API also offers the following events. fullscreenchange This event is fired by the document when an element enters or exits the full screen mode. fullscreenerror This event is fired by the element in case of failure (the full screen mode is not available for that element or for the document). The requestfullscreen() method and the fullscreenerror event are associated with the elements in the document, but the rest of the properties, methods, and events are part of the Document object, and therefore they are accessible from the document property.

Listing 1: Taking a <video> element full screen <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>full Screen</title> <script> var video; function initiate() { video = document.getelementbyid("media"); video.addeventlistener("click", gofullscreen); function gofullscreen() { if (!document.webkitfullscreenelement) { video.webkitrequestfullscreen(); video.play(); window.addeventlistener("load", initiate); </script> </head> <body> <section> <video id="media" width="720" height="400" poster="poster.jpg"> <source src="trailer.mp4"> <source src="trailer.ogg"> </video> </section> </body> </html> In the code in Listing 1, we add a listener for the load event to the window to execute a function called initiate() as soon as the document is loaded. When the event is fired, this function adds a listener for the click event to the <video> element. In consequence, the gofullscreen() function, set as the listener of this event, is executed every time the user clicks on the video. In this function, we use the fullscreenelement property to detect whether an element is already in full screen mode or not, and if not, the video is made full screen by the requestfullscreen() method. At the same time, the video is played with the play() method. IMPORTANT: This is an experimental API. The properties, methods, and events have been prefixed by browsers until the final specification is implemented. In the

case of Google Chrome, instead of the original names we have to use webkitrequestfullscreen(), webkitexitfullscreen(), webkitfullscreenchange, webkitfullscreenerror and webkitfullscreenelement. For Mozilla Firefox, the names are mozrequestfullscreen(), mozcancelfullscreen(), mozfullscreenchange, mozfullscreenerror and mozfullscreenelement. Full Screen Styles Browsers adjust the dimensions of the <video> element to the size of the screen automatically, but for any other element, the original dimensions are preserved, and the free space on the screen is filled with a black background. For this reason, CSS includes a pseudo-class called :full-screen to modify the styles of the element when it expands to full screen. IMPORTANT: The last specification declares the name of this pseudo-class without the hyphen (:fullscreen), but, at the time of writing, browsers like Mozilla Firefox and Google Chrome have only implemented the previous specification and work with the name mentioned in this guide (:full-screen). It also has to be prefixed to work properly (:-webkit-full-screen, :-moz-full-screen, etc.). Listing 2: Taking any element full screen <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>full Screen</title> <style> #player:-webkit-full-screen, #player:-webkit-fullscreen #media{ width: 100%; height: 100%; </style> <script> var video, player; function initiate() { video = document.getelementbyid("media"); player = document.getelementbyid("player"); player.addeventlistener("click", gofullscreen); function gofullscreen() { if (!document.webkitfullscreenelement) { player.webkitrequestfullscreen();

video.play(); else { document.webkitexitfullscreen(); video.pause(); window.addeventlistener("load", initiate); </script> </head> <body> <section id="player"> <video id="media" width="720" height="400" poster="poster.jpg"> <source src="trailer.mp4"> <source src="trailer.ogg"> </video> </section> </body> </html> In Listing 2, we take the <section> element and its content full screen. The gofullscreen() function is modified to activate and deactivate the full screen mode for this element. As in the previous example, the video is played when it is in full screen mode, but now it will be paused when the mode is canceled. These improvements are insufficient to make our player full screen. In full screen mode, the new container for the element is the screen, but the original dimensions and styles for the <section> and <video> elements are preserved intact. Using the :fullscreen pseudo-class, we change the values of the width and height properties of these elements to 100%, matching the dimensions of the container. Now the elements occupy the whole screen and truly reflect the full screen mode. Do It Yourself: Create a new HTML file to test the examples in this guide. Once the document is opened in the browser, click on the video to activate the full screen mode and click again to deactivate it.

Quick Reference Properties fullscreenelement This property returns a reference to the element that is in full screen mode. If no element is full screen, the property returns null. fullscreenenabled This Boolean property returns true when the document is able to go full screen or false otherwise. Methods requestfullscreen() This method is available for every element in the document. It activates full screen mode for the element. exitfullscreen() This method is available for the document. If an element is in full screen mode, the method cancels the mode and returns the focus back to the browser window. Events fullscreenchange This event is fired by the document when an element enters or exits the full screen mode. fullscreenerror This event is fired by the element in case of failure (the full screen mode is not available for that element or for the document).

For Masterminds Book Series for more Books and Quick Guides visit www.formasterminds.com