Scaling CSS Transform to Match Window Size

I have tried many solutions, but none seem to work for me.

Here is the code I am using:

$(function() {
  $(".zoom-close").on("click", function() {
    $(".zoom-close").toggleClass("transform", 1000);
    $(".img").toggleClass("active", 1000);
  });
});
body {
  background: red;
  width: 100%;
  margin: 0;
}

.col {
  width: 30%;
}

.img {
  display: block;
  transition: all 0.5s ease;
  position: relative;
  transition: all 0.5s ease;
  -webkit-transition: 1s
}

// CSS code continues...

.zoom-close.transform .zoom-inner {
  opacity: 0;
  transition: all 0.5s ease;
}
// Further CSS properties...

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<div class="col">
  <div class="img">
    <img src="https://via.placeholder.com/250">
    <button class="zoom-close">
      <div class="zoom"><span class="zoom-inner"></span> </div>
    </button>
  </div>
</div>

I need assistance with the following problem statement:

<div class="img"> should adjust to fit the window size (100% width) when the

<button class="zoom-close">
is clicked while maintaining a similar effect as the transform property.

(Please note: While the CSS transform property is not mandatory, I require an effect similar to it.)

Answer №1

To accurately determine the screen dimensions such as width and height during a zoom event, follow these steps:

HTML Setup

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<div class="col">
  <div class="img">
    <img src="https://via.placeholder.com/250"  >

  </div>
    <br><br><br>
    <button class="zoom-close">
      <div class="zoom"><span class="zoom-inner"></span> </div>
    </button>
</div>

JavaScript Functions

var flag=0;
$(function() {
  $(".zoom-close").on("click", function() {
    $(".zoom-close").toggleClass("transform", 1000);
   // $(".img").toggleClass("active", 1000);
   var height= window.screen.height;
   var width = window.screen.width;

   if(flag == 0){
        $("img").css("width", "15vw");
        $("img").css("height", "15vw");
        flag=1;
   }
   else{
        $("img").css("width", "100vw");
        $("img").css("height", "100vw");
        flag=0;
   }

  });
});

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

Establish individual states for every dynamically created component using the same handler function

I have a component in React built with Material UI, where the child component (Paper) is dynamically generated depending on the number of items in an array. The challenge I'm facing is changing the elevation property of the Paper component when it&ap ...

How can I prevent dataTable resizing?

Is there a solution to prevent datatable resizing? For instance, when the default number of rows per page in the datatable is set to 10 rows. If you input 13 rows into the datatable, it will be divided into 2 pages - with 10 rows on the first page and 3 ro ...

The Angular ngFor loop seems to be stuck in an endless cycle while trying to display

I'm currently in the process of creating a Logbox for my web application. It is designed to receive an Array of logs and display them row by row within a div. I am utilizing ngFor to iterate through my Array of logs and then present them. However, I& ...

Stop a loop that includes an asynchronous AJAX function

Embarking on my Javascript journey as a beginner, I find myself facing the first of many questions ahead! Here is the task at hand: I have a directory filled with several .txt files named art1.txt, art2.txt, and so on (the total count may vary, which is ...

Retrieving entities from a text

I found a script on the Webdriver.io website that looks like this (adjusted for testing) const { remote } = require('webdriverio'); var assert = require('assert'); ;(async () => { const browser = await multiremote({ ...

Retrieve input value in Angular 8 using only the element's ID

Can the value of an input be obtained in Angular 8 with TypeScript if only the element's id is known? ...

Using Vue.js's ref within a v-for iteration

When attempting to utilize components within a v-for loop and initialize the ref for future access to their methods from the parent component, I encountered an issue. Below is a simplified version of the code that demonstrates my scenario: <template> ...

Guide to attaching data to an AJAX request

I'm new to ajax and recently encountered an issue while working on a project where I needed to send a query from an HTML form. However, I've been unable to send any data for some reason. I tried sending FormData through the xmlhttprequest.send() ...

Using NextJS to pass a string from an input field to getStaticProps via context

I am a beginner in NextJS and React, so please forgive my lack of knowledge. I am trying to figure out how to pass the text input by users from an input field (inside Header) to the getStaticProps function of a specific page using the React context API. I ...

Error: Unable to assign value to '18dit075' property as it is not defined in Node.js

var id = req.query.id; var username = req.query.name; var password = req.query.password; console.log(req.query); var data = { people:{ } } data.people[id] = { username: username, password: password, ...

What is the best way to preload images from an array within another array?

I am encountering an issue with preloading images. for(y=0;slide_image.lenght;y++){ for(x=0;slide_image[y].lenght;x++){ var preload_image=new Image(); preload_image.src=slide_image[y][x];} } When I use preload_image.src=slide_image[x] alon ...

Accessing the state value within the render method in ReactJS can provide crucial information

Just starting out with React and ran into an issue while trying to pass state in constructor to the render method. My h1 element is not showing up on the screen. Any idea what I might be doing wrong? class Mod extends React.Component { constructor( ...

Determining User Consent: A Straightforward Guide to Identifying Previously Accepted Cookie Consent

I've been tasked with adding a cookie to a website. The site only tracks the number of visits, so there is no user-specific data available for cookie assignment or acknowledgment tracking. Is it possible to show the cookie notification only to users ...

Purge POST request cache in Node.js

Currently, I have implemented nodemailer to enable users to contact me via email. Once the form data is submitted successfully, the page redirects to my homepage as intended. However, if an attempt is made to refresh the page, a confirmation alert pops up ...

"Troubleshooting: Issue with React's useState and useEffect functions in conjunction with localStorage

Encountering a challenge with a React component using useState and useEffect hooks to handle state and maintain it in localStorage. The component aims to create a collapsible section with a heading and content, where the expanded state is stored in localSt ...

Performing AJAX request without relying on jQuery for a bookmarklet

I'm facing a challenge with my bookmarklet that saves a webpage's URL along with the current user's ID from my application. The issue is that it only works on pages with jQuery available, and I need to perform an AJAX call without relying on ...

Is it possible to use async/await together with forEach in JavaScript?

Within my array of objects containing user information and emails, I aim to send emails using AWS SES. To accomplish this, I must decide between utilizing await or normal .then. Preferably, I would like to use await within a forEach loop. Is it feasible to ...

Rails: Generating HTML output straight from the controller

Looking for some guidance on handling the response from an AJAX call. Here's what I'm trying to achieve: Initiate an AJAX call to my Rails application to retrieve an HTML document. In the Rails controller, access the HTML document stored on dis ...

Boosting numbers using ajax in combination with PHP and MySQL

My requirement is for it to fit in and when I click on a file, the number should increase to 1 and be saved in the database. I have already set up the database and have part of the AJAX code ready. The issue is that when the number increments, the page up ...

Challenges with Adjusting Background Opacity in CSS

My text has a white background with an opacity of .3, but it's affecting the foreground due to CSS repositioning. Even though the HTML is in a different division, I struggle with certain aspects of CSS and would appreciate guidance from those more exp ...