DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations

Trending

  • The SPACE Framework for Developer Productivity
  • Microservices Decoded: Unraveling the Benefits, Challenges, and Best Practices for APIs
  • How To Check IP Addresses for Known Threats and Tor Exit Node Servers in Java
  • A Complete Guide to AWS File Handling and How It Is Revolutionizing Cloud Storage
  1. DZone
  2. Data Engineering
  3. Databases
  4. Using HTML5's FullScreen API

Using HTML5's FullScreen API

Sagar Ganatra user avatar by
Sagar Ganatra
·
May. 08, 12 · Interview
Like (0)
Save
Tweet
Share
16.59K Views

Join the DZone community and get the full member experience.

Join For Free

I've been looking into ways in which a web application can be made more user friendly and HTML5 does include some powerful features such as PageVisibility, Navigation Timing, etc,. that can be used to provide good user experience. Today I was looking into FullScreen API that allows you show any of the elements in the DOM in Full-Screen mode. Suppose you have a HTML5 video embedded in a page and would like to play that video in full-screen mode then it is now possible with the FullScreen API. Similarly say if you have an image element, it can also be shown in full screen mode.

To present a element in the full-screen mode you have to call the method requestFullScreen() on that element. I've created a demo that shows a picture and when you click on a button it shows it in the full-screen mode and then changes the picture every three seconds creating a slideshow like experience. 


Here's the code:
<!DOCTYPE HTML> 
<html> 
<head> 
<script type="text/javascript"> 
	//list of images for the slideshow 
	var imageList = ["Image3.jpg", "Image4.jpg", "Image5.jpg"]; 
	var count = 0; 

	//invoke this when user wants to see a Full Screen Slideshow 
	function enterFullScreen(){ 
		var elem = document.getElementById("slideshow"); 
		//show full screen 
		elem.webkitRequestFullScreen(); 
		setTimeout(changePicture, 3000); 
	} 

	function changePicture(){ 
		count++; 
		//cycle through the list of images 
		document.getElementById("image1").src = imageList[count % imageList.length]; 
		if (document.webkitIsFullScreen) 
			setTimeout(changePicture, 3000); 
		else 
			//if user exits the full screen mode
			 document.getElementById("image1").src = imageList[0]; 
	} 
</script> 
</head> 
<body> 
	<div id="slideshow"> 
		<img id="image1" src="Image3.jpg"><img> 
	</div> 
	<br> 
	<input type="button" value="Enter full screen mode" onclick=enterFullScreen()> 
</body> 
</html>
When you click the button - 'Enter full screen mode' it calls the user defined method - enterFullScreen. In this method a call is made to the method webkitRequestFullScreen on the element that we want to show in full-screen mode. I'm using Google chrome and hence the method requestFullScreen with a prefix 'webkit'. On firefox it would be 'moz'. A slideshow like effect is created by looping through the images in the function changePicture.

To exit from the full-screen mode you can press the 'Esc' key. In the changePicture method I'm checking whether the full-screen mode is still activated by referring to the variable webkitIsFullScreen defined in the document object. It returns true if full-screen mode is activated and false otherwise. 


 
API HTML

Published at DZone with permission of Sagar Ganatra, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Trending

  • The SPACE Framework for Developer Productivity
  • Microservices Decoded: Unraveling the Benefits, Challenges, and Best Practices for APIs
  • How To Check IP Addresses for Known Threats and Tor Exit Node Servers in Java
  • A Complete Guide to AWS File Handling and How It Is Revolutionizing Cloud Storage

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: