Enhance photo size without scale feature

Innovative Concept
I am currently working on developing a unique carousel design. The main concept is to have the image gradually zoom in at the beginning of each carousel "page".

The Challenge In order to achieve the desired outcome, I experimented with changing the scale of the background image using a transition effect. By enclosing it in a container with overflow:hidden, I was able to make it work smoothly. However, a new issue arose when trying to start the next carousel page with the image "zoomed out" again. Resetting the scale back to 1 didn't provide an instant zoom-out effect due to the ongoing CSS transition.

One potential solution would be to temporarily remove the class from the element, reset the scale, and then reapply the class. Strangely, this approach did not yield the expected results.

An additional challenge is the limited browser support for the scale property: https://caniuse.com/?search=scale

Sample Code Snippet

let scaled = false;

const test = document.getElementById("test");

window.addEventListener("click", function()
{
  
  if(scaled)
  {
    // Remove the class
    test.classList.remove("foo");
    
    scaled = false;
    
    // Reset the scale
    test.style.transform = "scale(1)";
    
    // Add class back in making sure the animation should be updated
    window.requestAnimationFrame(() => {
      test.classList.add("foo");
    });
  }
  else
  {
    // Leave the animation running
    scaled = true;
    test.style.transform = "scale(0.5)";
  }
  
  
})
.foo {
  width: 500px;
  height: 500px;
  background: blue;
  transition: transform 2s;
}
<div id="test" class="foo">
</div>

For optimal performance, run the above code snippet in Firefox or Safari since other browsers do not fully support the scale feature at this time.

Upon first click, the animation behaves as intended. However, on subsequent clicks, the animation persists despite removing the class.

Seeking Guidance
Is there an alternative technique to achieve a similar effect without relying on scale? Why does the animation continue even after removing the class?

Answer №1

This particular issue revolves around the concept of Event Loop. You may experiment with this suggested fix involving width, although its efficacy in fully meeting your requirements is uncertain.

const test = document.getElementById("test");

window.addEventListener("click", function()
{
      test.style.transition = 'none'
      test.style.width = '100%';
      
      
      window.requestAnimationFrame(() => {
        test.style.width = "50%";
        test.style.transition = 'width 2s'
      });
})
.foo {
  width: 500px;
  height: auto;
  background: blue;
}
<img src="https://images.freeimages.com/images/large-previews/76e/abstract-1-1174741.jpg" class="foo" id="test"/>

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

Issues with Laravel 5.8 and Bootstrap not functioning properly in Jquery

Check out this link for using Bootstrap Select. The code works perfectly in the view, but when I try to implement it with jQuery below, it doesn't work. Can someone help me fix this issue? View Code: <table id="tableAppointment" style=&q ...

Adding a unique key to every element within a JavaScript array

I am working with the array provided below which contains simple values. My goal is to add a key id before each value in the array, resulting in something like this: ["id:a", "id:b","id:c","id:d"]. Is there an easy way to achieve this? Any assistance would ...

Tips for duplicating a collada model in three.js?

I've imported a .dae model into my scene and I want to use it multiple times. The code provided works with meshes, but the collada.scene object is not a mesh: var mesh2 = new THREE.Mesh( loadedMesh.geometry, loadedMesh.material ); Is there a way to ...

Struggling to line up columns using Bootstrap 4

Currently, I am delving into web design and working on a mock website. My knowledge of Bootstrap, CSS, and HTML is limited, which has led me to encounter some challenges. Despite dedicating the entire morning to this project, I find myself stuck with align ...

`I am experiencing issues with the HTTP Post functionality`

Whenever I click on the button displayed in the index.html code, an error occurs when the "$http.post" call is made. The web page then displays an alert saying 'Error!', preventing me from saving the new JSON file due to this issue. I need help ...

Error message: Upon refreshing the page, the React Router is unable to read properties of

While developing a recipe application using the Edamam recipe API, everything was functioning smoothly until an issue arose when refreshing the Recipe Detail page. The error occurs specifically when trying to refresh the page with a URL like http://localho ...

I am encountering an issue with running my Mocha tests. Can anyone provide assistance on how to solve this problem?

https://i.sstatic.net/kLnxs.png Could the issue be with the package.json file or am I not executing the proper command to run it? ...

Combining AngularJS with Bridgeit.js for a seamless mobile web app experience

Currently, I'm working on an AngularJS web application that requires scanning a package from a mobile device. To achieve this functionality, I am utilizing BridgeIt. Unfortunately, the code I've written in Angular doesn't seem to be functio ...

Receiving an unknown value from the input field

I can't seem to retrieve the value of my input, as quantityElement.Value consistently returns undefined. Here is the section of my HTML and JS that I am struggling with. In my JavaScript function, the quantityElement always gives me an undefined whe ...

Converting CSS properties to MaterialUI Styles in ReactJS: A step-by-step guide

In my CSS, I've included the following code: [contentEditable=true]:empty:not(:focus):before{ content:attr(data-text) } This snippet allows me to display a placeholder inside a content-editable div when it is empty. Since I am using Material-UI ...

A pattern matching formula to eliminate specific characters from the beginning to the end of a string

I am facing an issue with extracting content from a given string: var string = "From: Sarah<br /> Sent: 10 May 2021 09:45:20</br /> To: Alice<br /> Subject: Meeting Reminder<br /><br /> Hi Alice, <br /> Here is a ...

Creating a pop-up effect for a div in the center of a table cell using HTML and CSS

I am currently working with Angular and facing a challenge where I need to display a div like a popup in a table cell when clicked. Despite having the click event logic in place, I am unsure of how to achieve this without using external libraries such as B ...

Retrieve jQuery CSS styles from a JSON database

I've been attempting to pass CSS attributes into a jQuery method using data stored in a JSON database. However, it doesn't seem to be functioning as expected. I suspect that directly inputting the path to the JSON variable may not be the correct ...

Is applying a bevel effect when hovering achievable?

Is there a way to add a bevel effect to my hyperlink image so it stays in place without moving down? I need the bevel effect to be inside the image as it keeps shifting position. Any suggestions would be greatly appreciated. I really need the bevel effect ...

Using Various Buttons in a Bootstrap Form

I have implemented Bootstrap to create a form. The form structure is as follows: <form action="default_results.php" method="post" class="calculator" name="frmCalculator"> At the beginning of my code, I used the above form code. At the end of the pa ...

Showing the loading screen while waiting for the static Next.js app to load

Looking for a way to implement a loading screen right before the entire static page finishes loading? I'm currently utilizing modules:export to create my static page, but struggling to listen to the window load event since NextJs has already loaded th ...

Combine several svg elements within a single div row using Bootstrap 5

Is there a way to adjust the SVG settings in order to have two of them side by side within a div class="col" element? ...

Safeguarding intellectual property rights

I have some legally protected data in my database and I've noticed that Google Books has a system in place to prevent copying and printing of content. For example, if you try to print a book from this link, it won't appear: How can I protect my ...

Converting Database Information to JSON Format for Mobile Authentication Form

Currently, I am working on a Mobile App project using Phonegap that requires users to log in before retrieving JSON data. This PHP page is responsible for connecting to the mobile site and fetching the necessary information. <?php $con = mysqli_connec ...

Solving issues with flexboxes in Safari 5.1.7 on Windows

I am currently utilizing flex boxes for managing the layouts of my website. However, it seems that the Safari version for Windows (5.1.7) is outdated and causing all flex boxes to be dysfunctional. On MacOS systems, the same version 12.x works correctly. ...