Learn the simple trick to switch to full screen by just clicking

import { Component, OnInit, ElementRef } from '@angular/core';
declare var JQuery : any; 

@Component({
  selector: 'app-presentation',
  templateUrl: './presentation.component.html',
  styleUrls: ['./presentation.component.scss']
})
export class PresentationComponent implements OnInit {

  public count=0;
  public imgUrl ='http://192.168.1.90:8080/pdf/temp';

  constructor( public _eleRef : ElementRef ) {
    this.count=0
    this.imgUrl='http://192.168.1.90:8080/pdf/temp'+this.count+".jpg"
   }

  ngOnInit() {
    jQuery(this._eleRef.nativeElement).find('#Fullscreen').on('click',function(){
        jQuery('#exampleImage').width(jQuery(window).width());
        jQuery('#exampleImage').height(jQuery(window).height());
     });
  }

  back(){this.count--;
    if(this.count>=0 && this.count<13){
    
    this.imgUrl='http://192.168.1.90:8080/pdf/temp'+this.count+".jpg"
    }
     else{
      this.count++;
    }
  }

  next(){this.count++;
     if(this.count>=0 && this.count<13){
    
    this.imgUrl='http://192.168.1.90:8080/pdf/temp'+this.count+".jpg"
     }
    else{
      this.count--;
    }
  }

}
.slide-control {
    z-index: 5;
    background-color: #323232;
    overflow: hidden;
    border: 0;
    padding: 0;
    width: 100%;
    color: #fff;
    font-size: 13px;
    max-height: 56px;
    min-height: 50px;
    ///text-align: center;
}

.control {
    font-size: 20px;
    padding: 10px;
    cursor: pointer;
}

.slide-control #fullscreen {
    float: right !important;
}

.imageArea {
    background-color: #e5e5e5;
    border: 1px inset #323232;
}
<div class="row imageArea">
    <div class="mx-auto">
        <img [src]="imgUrl" id="exampleImage" class="img-fluid" alt="Responsive image">
    </div>
    <div class="slide-control form-inline">
        <div class="mx-auto">
            <span class="control" (click)="back(count)"><i class="fa fa-arrow-left" aria-hidden="true"></i></span>
            <span>{{count+1}} / 13</span>
            <span class="control" (click)="next(count)"><i class="fa fa-arrow-right" aria-hidden="true"></i></span>
        </div>
        <div class="fullscreen float-right">
            <span class="control" id="Fullscreen"><i class="fa fa-arrows-alt text-right" aria-hidden="true"></i></span>
        </div>
    </div>
</div>

hello, I am developing my own presentation viewer using Angular 2. I have implemented a fullscreen button that zooms the image to the size of the container when clicked. However, I would like to make this button toggleable. This means that when clicked again, it should display the zoomed image in its original size, as it was when the page loaded initially.

Answer №1

Give this a try!

function enterExitFullScreen() {
  if (!document.fullscreenElement && 
      !document.mozFullScreenElement && 
      !document.webkitFullscreenElement && 
      !document.msFullscreenElement
  ) {
    if (document.documentElement.requestFullscreen) {
      document.documentElement.requestFullscreen();
    } else if (document.documentElement.msRequestFullscreen) {
      document.documentElement.msRequestFullscreen();
    } else if (document.documentElement.mozRequestFullScreen) {
      document.documentElement.mozRequestFullScreen();
    } else if (document.documentElement.webkitRequestFullscreen) {
      document.documentElement.webkitRequestFullscreen();
    }
  } else {
    if (document.exitFullscreen) {
      document.exitFullscreen();
    } else if (document.msExitFullscreen) {
      document.msExitFullscreen();
    } else if (document.mozCancelFullScreen) {
      document.mozCancelFullScreen();
    } else if (document.webkitExitFullscreen) {
      document.webkitExitFullscreen();
    }
  }
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Creating a resilient node websocket client with enhanced security (overcoming the challenge of verifying the initial certificate)

What's Working? I successfully created a node server using WebSocket technology. I used the library WebSocket-Node and added key/cert to my HTTPS/secure websocket server as shown below: import WebSockerServer from "websocket"; import fs fro ...

Image upload failed after a successful submission using an HTML form

My PHP website is custom-built and hosted on a Plesk (Windows Hosting Server of Godaddy) After submitting a form, all values are updated except for the image. The error message displayed on the page is as follows: PHP Warning: move_uploaded_file(../../.. ...

Eliminate any unnecessary space below a list item and ensure it is justified

I need help with some extra indentation that is appearing under an ordered list I have created. I want to eliminate the extra spacing to achieve a cleaner look. This is how I want it to appear: https://i.sstatic.net/O7cyG.png However, it currently looks ...

The AJAX POST function is not functioning properly when clicking on contextmenus

Can someone please assist me? I am having trouble sending data via ajax post to my nodejs server from contextmenus. It is not functioning as expected. Although the ajax request does not give any error alert, the data is not being sent successfully. I hav ...

What is the best way to click within a web browser control?

I'm attempting to automate the process of clicking a specific div id button using vb.net. I have integrated a webbrowser for this purpose, and here is my current code snippet. The goal is to click the 'Do Job' button on the website through v ...

Having trouble compiling for IOS using a bare Expo app? You may encounter an error message that reads "Build input file cannot be found."

Encountering Error When Running react-native run-ios on Bare Expo App I am experiencing an issue while trying to run the 'react-native run-ios' command on my Bare expo app. The error message I am receiving is: "Build input file cannot be found: ...

Creating separate files for establishing DB connection and writing Node.js queries is a recommended practice for organization

Having an issue with connecting dbconnection.js and demo_api_select.js. When trying to declare a variable in demo_api_select.js, I am encountering errors like this: Error Notification Please assist me in resolving this problem. dbconnection.js: var ...

Eliminating the need for RequireJS in the Typescript Visual Studio project template

After integrating RequireJS into my Typescript template using the nuget package manager, I found that it was more than what I needed and decided to uninstall it. Even though I removed the package through nuget and the files were deleted properly, my Typesc ...

Alignment of a Definition List with Omissions of Definitions

Often, I come across applications with forms containing optional fields. In the Show view, these fields tend to "collapse" together and lose alignment with their corresponding labels. For instance, if I have 3 fields that should be displayed as: Phone: 3 ...

Ignore Express routes with file extensions

My goal is to streamline my routing process with AngularJS without having to duplicate route specifications in both Express and Angular. To achieve this, I set up a "catch all" route as shown below: app.use('/api', api); // handling server-side ...

What steps are involved in making select fields that change dynamically?

There are two fields available for the user to interact with: size and design. Users have the ability to add more instances of these fields as many times as they desire. Illustration: If I choose M for the size, it will display in the console: https://i ...

Ways to keep track of Angular Watchers within a web page

Is there a reliable method to accurately count the number of watchers on a page? I have come across various articles that provide different ways to do it, but each gives me conflicting counts, making it difficult to determine the correct approach. A Stac ...

Clicking on a link initiates the dropdown menu for selecting an option

This project is specifically designed for mobile use, so there's no need to worry about how it will appear on desktop screens. In this project, I have an "a href" with an icon next to it that simulates a button. When a user clicks on it, a dropdown me ...

Persist the scroll position within a div even after refreshing a PHP file using AJAX

I have a specific div set up with its own scroll bar, which is being refreshed using AJAX (with a PHP file). Whenever I scroll within this div and trigger a reload, the inner scrollbar resets back to the top. My goal is to retain the position of the scroll ...

Stop image uploads immediately with the jquery.filer plugin

Currently, I am utilizing the jquery.filer plugin which can be found here. The plugin is functioning well for me except for one issue - when I select images, they are getting uploaded immediately. Is there a way to disable this feature? My preference is ...

Including a JavaScript library in a Maven project with JSF

Currently, I am working on a JSF project with Maven and I am utilizing a JavaScript library for developing a 3D graphics interface. I am looking for a way to add/import this JS library into my project without the need to manually move/copy all the JS files ...

Displaying nested object properties in HTML through iteration

What is the correct way to access them if item.NestObj.textpropertyVal is showing incorrect? success: function(data){ var html = ""; $.each(data.mainOutterObj, function (index, item) { html += "<ul&g ...

HTML script tag without a specified type

Exploring asp.net and frontend technologies for the first time. The code snippet I'm working with is as follows: <ul> @foreach (var item in Model) { <li> <img src="@item" alt="file here" width="100" height=" ...

How can I ensure that the height of my dropdown menu covers the entire screen without being limited by the page height

I'm trying to adjust a dropdown menu so that it fits perfectly within the screen size, covering the entire height without showing any content beneath or below it. Currently, the menu covers the screen on some pages but scrolls and appears too large du ...

Having trouble with Array.filter functionality

Despite the multitude of discussions on this topic, I have not been successful in using the Array.filter method to remove an item from a string-based Array. Below is an example of the filter method being used in the context of mutating a Vuex store. UPDAT ...