Maximize, enlarge, and modify the size and appearance of the element's style as

Communicating in English is a bit challenging for me, so I may struggle to provide clear explanations. Nonetheless, I will do my best to articulate my thoughts. Please accept my sincere apologies for any confusion.

I am currently working on implementing a thumbnail-to-fullscreen transition effect. Similar to the one seen on Google Photos, when a thumbnail is clicked, it should expand to fullscreen view with a smooth animation.

Here's my approach: Upon clicking a thumbnail, I create a duplicate (clone) of that element. Next, I apply initial styles to the clone (such as top, left, width, and height) to match those of the original element. Then, I add a specific CSS class to the clone that positions it correctly for the full expanding effect (setting width to 100vw, height to 100vh, top to 0, left to 0, and position to fixed using the ".fullscreen" class). I found some inspiration from this example.

However, while setting these styles,

clone.style.top = rect.top;
clone.style.left = rect.left;
clone.style.height = img.offsetHeight
clone.style.width = img.offsetWidth

This method inadvertently overrides the top, left, height, and width attributes of all child elements within the clone, even if they have their own classes set. It also fails to trigger the "fullscreen" class behavior. Consequently, the transformation or expansion effect does not occur, and the clone retains its original style. If I omit setting these styles, the transform animation will not be properly applied.


How can I successfully achieve a fullscreen expand transform animation? Is there a more effective solution available? Or is there a way to define an element's initial style without interfering with additional classes added via JavaScript?

Once again, I sincerely apologize for any language barriers. I have put forth my best effort to convey my ideas accurately.
By the way, I'm puzzled as to why element.style is not functioning in the code snippet provided.

function handler(element)
{
var type = element.getAttribute("data-type")
  switch(type)
{
    case "image":
      transition_fullscreen(element);
      break;
    default:
      break;
  }
}
function transition_fullscreen(element)
{
  var img = element.getElementsByClassName('el_view')[0];
var rect = img.getBoundingClientRect();
var clone = img.cloneNode(true);
  clone.style.top = rect.top;
clone.style.left = rect.left;
  clone.style.height = img.offsetHeight
  clone.style.width = img.offsetWidth
clone.classList.add('fullscreen');
  var ap = document.getElementById('form').appendChild(clone);

}
#form 
{
width: 100%;
text-align:center;
}

#form .element 
{
display:inline-block;
float:left;
width: 10%;
height: 20%;
margin: 1.9em;
cursor: default; 
transition: background .1s ease-in-out;
animation:animatezoom 0.5s;
}

#form .highlight
{

padding:14px;
transition: transform .1s ease-out;
padding-top:auto;
/*border: 1px solid #ddd;
    border-radius: 4px;*/
}
#form .highlight:hover { transform: translateY(-0.5rem) scale(1.0125);
box-shadow: 0 0.5em 1.9rem -1rem rgba(0,0,0,0.5); }
#form .highlight:active { transform:scale(0.8); }

#form .el_img { max-height: 124px; vertical-align: middle; }
#form .el_img img { max-width: 88px; max-height: 124px; margin-top: 5%; border-radius:5px; box-shadow:0 2px 5px 0 rgba(0,0,0,0.16),0 2px 10px 0 rgba(0,0,0,0.12); border-radius:5px;
opacity: 1;
transition: all 3s;
}

#form .el_img .fullscreen
{
z-index:9999;
max-width:100vw;
max-height:100vh;
width:100vw;
height:100vh;
position:fixed;
top:1%;
left:1%;
  transition: all 3s;
}
<div id="form">
  <div id="element#somefile.exe" class="element" data-type="image" data-link="somefile.exe" onclick=handler(this); title="somefile.exe"> 
          <div id="highlight#somefile.exe" class="highlight"> 
            <div id="content#somefile.exe" class="content"> 
              <div id="el_img#somefile.exe" class="el_img"> 
                <img id="view#somefile.exe" class="el_view" src="https://lh3.googleusercontent.com/oKsgcsHtHu_nIkpNd-mNCAyzUD8xo68laRPOfvFuO0hqv6nDXVNNjEMmoiv9tIDgTj8=w170"> 
              </div> 
              <div id="el_name#somefile.exe" class="el_name"> 
                somefile.exe 
              </div> 
            </div> 
          </div> 
        </div>
        <div id="element#somefile.exe" class="element" data-type="image" data-link="somefile.exe" onclick=handler(this); title="somefile.exe"> 
          <div id="highlight#somefile.exe" class="highlight"> 
            <div id="content#somefile.exe" class="content"> 
              <div id="el_img#somefile.exe" class="el_img"> 
                <img id="view#somefile.exe" class="el_view" src="https://lh3.googleusercontent.com/hYQO8ekNvsPWMSzMe6IZdCAT6p8qq-SlzA0jiZstV7qBcWg5kn-39qHY0ZaBPqd3usc=w170"> 
              </div> 
              <div id="el_name#somefile.exe" class="el_name"> 
                blahblah.exe
              </div> 
            </div> 
          </div> 
        </div>
        <div id="element#somefile.exe" class="element" data-type="image" data-link="somefile.exe" onclick=handler(this); title="somefile.exe"> 
          <div id="highlight#somefile.exe" class="highlight"> 
            <div id="content#somefile.exe" class="content"> 
              <div id="el_img#somefile.exe" class="el_img"> 
                <img id="view#somefile.exe" class="el_view" src="https://lh3.googleusercontent.com/UMB2HRRRAAzXAEaCM9Gg-baCaDx_1RTXHscW5k2Ge3P4KP4mwTt2m6oyEHBWex3c4SxU=w300"> 
              </div> 
              <div id="el_name#somefile.exe" class="el_name"> 
                mehhhhh.cool
              </div> 
            </div> 
          </div> 
        </div>
    </div>
    


Answer №1

I was the one who discovered this: If you're looking for your image in CSS, you should search for it like this: #form .el_img .fullscreen This code searches for elements in #form that are within .el_img and have a class of fullscreen. However, if you want an element in #form with both el_img and fullscreen classes, you need to remove the space before .el_img so it looks like this:

#form .el_img.fullscreen {
 /* Add the rest of your code here */

If you make this change, it will work perfectly.
Check out the demo link here: https://www.w3schools.com/code/tryit.asp?filename=FOBUOKP41CYW

Answer №2

I have just created a design similar to Google Photos by incorporating HTML, CSS, and JS. This design is compatible with all your products.
Demo:

let modal = document.getElementById('myModal'),
  modalImg = document.getElementById('img01'),
  captionText = document.getElementById('caption');

function handler(e) {
  switch (e.getAttribute('data-type')) {
    case 'image':
      transition_fullscreen(e);
  }
}

function transition_fullscreen(e) {
  modal.style.display = 'block',
    modalImg.src = e.children[0].children[0].children[0].children[0].src, captionText.innerHTML = e.children[0].children[0].children[1].innerHTML;
}
const close_btn = document.getElementsByClassName('close')[0];
close_btn.onclick = function() {
    modal.style.display = 'none';
  },
  window.onclick = function(e) {
    e.target == modal && (modal.style.display = 'none');
  };
#myImg,
.close {
  transition: .3s;
}

body {
  font-family: Arial, Helvetica, sans-serif;
}

#myImg {
  border-radius: 5px;
  cursor: pointer;
}

#myImg:hover {
  opacity: .7;
}

.modal {
  display: none;
  position: fixed;
  z-index: 1;
  padding-top: 100px;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  overflow: auto;
  background-color: #000;
  background-color: rgba(0, 0, 0, .9);
}

#caption,
.modal-content {
  margin: auto;
  display: block;
  width: 80%;
  max-width: 700px;
}

#caption {
  text-align: center;
  color: #ccc;
  padding: 10px 0;
  height: 150px;
}

#caption,
.modal-content {
  -webkit-animation-name: zoom;
  -webkit-animation-duration: .6s;
  animation-name: zoom;
  animation-duration: .6s;
}

@-webkit-keyframes zoom {
  from {
    -webkit-transform: scale(0);
  }
  to {
    -webkit-transform: scale(1);
  }
}

@keyframes zoom {
  from {
    transform: scale(0);
  }
  to {
    transform: scale(1);
  }
}

.close {
  position: absolute;
  top: 15px;
  right: 35px;
  color: #f1f1f1;
  font-size: 40px;
  font-weight: 700;
}

.close:focus,
.close:hover {
  color: #bbb;
  text-decoration: none;
  cursor: pointer;
}

@media only screen and (max-width:700px) {
  .modal-content {
    width: 100%;
  }
}
<!DOCTYPE html>
<html>

<head>
  <meta name="viewport" content="width=device-width, initial-scale=1">

</head>

<body>
  <div id="form">
    <div id="element#somefile.exe" class="element" data-type="image" data-link="somefile.exe" onclick=handler(this); title="somefile.exe">
      <div id="highlight#somefile.exe" class="highlight">
        <div id="content#somefile.exe" class="content">
          <div id="el_img#somefile.exe" class="el_img">
            <img id="view#somefile.exe" class="el_view" src="https://lh3.googleusercontent.com/oKsgcsHtHu_nIkpNd-mNCAyzUD8xo68laRPOfvFuO0hqv6nDXVNNjEMmoiv9tIDgTj8=w170">
          </div>
          <div id="el_name#somefile.exe" class="el_name">
            somefile.exe
          </div>
        </div>
      </div>
    </div>
    <div id="element#somefile.exe" class="element" data-type="image" data-link="somefile.exe" onclick=handler(this); title="somefile.exe">
      <div id="highlight#somefile.exe" class="highlight">
        <div id="content#somefile.exe" class="content">
          <div id="el_img#somefile.exe" class="el_img">
            <img id="view#somefile.exe" class="el_view" src="https://lh3.googleusercontent.com/hYQO8ekNvsPWMSzMe6IZdCAT6p8qq-SlzA0jiZstV7qBcWg5kn-39qHY0ZaBPqd3usc=w170">
          </div>
          <div id="el_name#somefile.exe" class="el_name">
            blahblah.exe
          </div>
        </div>
      </div>
    </div>
    <div id="element#somefile.exe" class="element" data-type="image" data-link="somefile.exe" onclick=handler(this); title="somefile.exe">
      <div id="highlight#somefile.exe" class="highlight">
        <div id="content#somefile.exe" class="content">
          <div id="el_img#somefile.exe" class="el_img">
            <img id="view#somefile.exe" class="el_view" src="https://lh3.googleusercontent.com/UMB2HRRRAAzXAEaCM9Gg-baCaDx_1RTXHscW5k2Ge3P4KP4mwTt2m6oyEHBWex3c4SxU=w300">
          </div>
          <div id="el_name#somefile.exe" class="el_name">
            mehhhhh.cool
          </div>
        </div>
      </div>
    </div>
  </div>
  <!-- The Modal -->
  <div id="myModal" class="modal">
    <span class="close">&times;</span>
    <img class="modal-content" id="img01">
    <div id="caption"></div>
  </div>



</body>

</html>

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

Insert HTML code into a specified location using a WordPress Plugin

How can I add a custom text to my WordPress website using a plugin in an HTML theme, and display it between the post and comments section? Is there a universal method for achieving this, regardless of the installed theme, so that I can effectively showcas ...

PHP not compatible with Fancybox iframe

I'm facing a simple problem that I can't seem to figure out. I have a button that, when clicked, opens a fancybox with an iframe displaying a page from my website. This page includes a form for sending an email. Everything works fine except that ...

Arranging an Array in Descending Order based on Frequency using JQuery and Javascript

Here is the current array: myArray = ["ABAB", "ABAB", "ABAB", "CDCD", "EFEF", "EFEF"] The goal is to count occurrences and sort them in descending order like this: ABAB 3 EFEF 2 CDCD 1 It's important to note that the contents of the array are dyna ...

Discovering precise text within an element using jQuery

I am facing an issue with matching the exact word of one of the spans inside a container to insert a banner. Despite trying different scripts, I can't seem to get it right. Initially, I attempted this script: $(document).ready(function(){ if ($(&ap ...

What is the reason behind the particles being set at the center of the x-axis in THREE.JS?

I'm currently learning THREE.JS and I'm facing some challenges while trying to create a particle system. The issue I'm encountering is that all the particles seem to be aligned in the center on the X-axis, while the Y and Z axes appear to be ...

observing numerous directories in Sass

Is there an efficient way to monitor multiple directories in sass using a shell script? This is what I currently have in my shell script: sass --style compressed --watch branches/mysite/assets/css/sass:branches/mysite/assets/css & sass --style compre ...

Extracting URLs using Selenium from specific cells within a table

While parsing a webpage table, I noticed that one of the columns contains a hyperlink. The structure of the table is as follows: <table id="GridView1"> <tbody> <tr> ... </tr> <tr> ...

The current context does not have a reference to TextBox

I am encountering an issue with my simple aspx page. Despite not using Master Content Page, I am seeing the following error: The name 'txtFirstName' does not exist in the current context Here is my Markup: <%@ Page Language="C#" %> &l ...

Discovering with jQuery

Can we actually change the background color of '.preview-inner' to yellow from "#change_color"? <div id = "form-container> <input class="color-picker" id="change_color" type="text"> <div class="replacer"> <div class= ...

Once AngularJS validation passes, proceed with a regular form submission

Seeking a solution for implementing AngularJS on an existing web application that requires a standard HTTP POST operation devoid of AngularJS. Has anyone discovered a workaround for this? I've tried various approaches like setting action="#" and acti ...

changing web pages into PDF format

I need to convert HTML to PDF on a Linux system and integrate this functionality into a web application. Can you suggest any tools that are capable of doing this? Are there any other tools I should consider for this task? So far, I have attempted the foll ...

Design that adapts to various screen sizes and devices

I'm facing an issue where the two elements are misaligned on mobile, even though they display perfectly on desktop. In some cases, the bottom element is partially hidden on the left side as shown here: Any suggestions on how to center these elements ...

Just starting to explore Node.js and wondering how to create a dynamic dropdown menu in a web application that pulls

Here is my node code: app.get('/block_name', function (req,res){ var sql='SELECT `block_name`,`block_id` FROM `tbl_block` '; connection.query(sql,function(err, result) { if (err) throw err; res.json(result); }); }); app.ge ...

Tips for executing a function only once within the animation loop in Three.js

Is there a way to call a function only once when a certain condition is met in Three.js? I am currently sampling the frames per second (FPS) to send it to an external service. The FPS is sampled and averaged over time, and the average value is sent after 1 ...

What is the best way to organize my comments, responses, and replies in an efficient manner?

I am currently working with Nodejs, Express, MySQL, and EJS. In my project, users can create posts and leave comments. They can also reply to comments or replies on those posts. However, I am facing a challenge in sorting the data into objects/arrays for ...

Splitting columns evenly in a table with a width of 100%

Welcome to my first query on this platform. Despite my efforts to search for a solution, I couldn't find an explanation as to why my code isn't functioning correctly in Internet Explorer (10+). I have created three divs displayed as cells, each ...

Watch for changes in a nested collection in Angular using $scope.$watch

Within my Angular application, there is a checkbox list that is dynamically generated using nested ng-repeat loops. Here is an example of the code: <div ng-repeat="type in boundaryPartners"> <div class="row"> <div class="col-xs- ...

Cannot access the gulp-angular-templatecache module

I am currently utilizing the gulp-angular-templacache tool. I have a task that is supposed to generate a module called templates and I included it as a dependency in my app module: Here are the configurations: templateCache: { file: 'tem ...

Ensure that the "select" dropdown menu remains a constant size

One section of my Android app, powered by JQuery Mobile, displays a table with a combobox. The issue arises when selecting the option with a very long text, causing the combobox to expand and show half of the table off-screen. My goal is to set the combob ...

Sorting dates and amounts in string format with Smart-table

Sorting is a breeze in smart-table, but what about when the date and amount are in string format? How can we sort them? app.controller('basicsCtrl', ['$scope', function (scope) {scope.rowCollection = [ {firstName: 'Laurent', ...