Establish the dimensions of the element to match the dimensions of a responsive image

Currently, I am working on implementing flippable images on my website. It is important to me that the "back" of these images matches the dimensions of the front image. The challenge I am facing is that I have applied the Bootstrap img-responsive class to my images, which means the dimensions of the "back" image need to adjust dynamically to align with the "front".

This is the approach I envision (although I understand that the CSS code provided is not feasible, it serves to demonstrate my objective). I am utilizing ng-animate for transitioning effects and revealing the initially hidden "back" while concealing the front (which I have successfully achieved).

html:

<img class="front img-responsive" src="path/to/img.jpg" alt="">

<div class="back">Information about the image</div>

css:

.back {
    height: [current height of .front]
    width: [current width of .front]
}

Answer №1

To retrieve the dimensions of an image with jQuery, you can use the following script to set them for a specified div:

<img class="front img-responsive" id="img" src="path/to/img.jpg" alt="">
<div class="back" id="info">Information about the image</div>

$(document).ready(function() {        
var img = document.getElementById('img');
var width = img.clientWidth;
var height = img.clientHeight;
$("#info").width(width).height(height);
});

View DEMO

Answer №2

Just stumbled upon v1.3+ which includes added support, not sure if this is how it will be utilized...

Check out the plunker demo = http://plnkr.co/edit/utsD4RimPB6RSKXnAlLi?p=preview

<!DOCTYPE html>  
 <html ng-app>  
  <head>  
   <link rel="stylesheet" href="style.css">  
   <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.0-rc.0/angular.js"></script>  
   <style>  
    .mydiv {  
     height: {{height}}px;  
     width: {{width}}px;  
     background-color: red;  
    }  
   </style>  
  </head>  
  <body style="width:100%;height:100%;">  
   <div class="mydiv" ng-init="height= 100; width=200">&
lt;/div>  
   h: {{height}} w: {{width}}  
  </body>  
 </html>  

Another example can be found here:

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

Unlimited looping in the compiling of nodes within the AngularJS framework on Internet Explorer 8

While developing my Angular application, I encountered an issue where it functions perfectly in most browsers except for IE8. Surprisingly, IE7 and IE9 work without any problems. Upon investigation, I discovered that Angular's compileNodes function i ...

Ensuring the continuous transmission of data frames is essential for WebSocket communication

Our system utilizes websocket technology to transmit user activity events such as clicks, mouse movement, scroll, input, and more. In addition to these events, we also send a snapshot of the HTML DOM. On average, the size of the HTML snapshot is approximat ...

Obtaining the source code in CKEditor while in edit mode with Rails

As a Rails developer, I recently utilized CKEditor in one of my applications. After writing a sample HTML source code in the editor and submitting it, the code displayed properly on the front-end as a GUI. However, when attempting to edit the source code f ...

Tips on aligning a div to the right of a headline

My goal is to have an orange circle image placed to the right of my headline <h2>. However, I am facing an issue where the circle jumps above the headline when I shrink the screen. How can I ensure that it stays on the right side no matter the screen ...

Transmit JSON Data via POST Method and Retrieve Using Node.js (Without the Use of Body Parser)

Can anyone help me with sending JSON data from HTML and receiving it in Node.js? I've been trying for hours and I'm getting frustrated. It seems like I'm close to a solution but no luck so far. In my VSCODE, the response is null (req.body = ...

Is it possible for a media query to target only 2 elements instead of all 3?

Currently, I am dealing with an older website for a client, and it appears that a media query is not correctly affecting three specific classes out of the total. These problematic classes are .free-ship, .wholesale, .chronicles The CSS styling for these c ...

The enigma of HTML forms never ceases to baffle

Currently, I am enrolled in a Vue.js course and have recently delved into the topic of forms and their management. The concept posed about how the < select > tag operates has left me puzzled. Is it correct to assume that its value corresponds to the ...

Maximizing the width of navbar elements with Bootstrap 3

I am currently working on building a webpage with bootstrap3, but I have encountered an issue with the navigation bar. I would like the navigation links ("Web Design", "Development", "Photography", "Blog") to be evenly spaced out within the horizontal na ...

Utilize page variables to activate audio clips upon clicking

Can someone assist me with a script that activates an audio clip when five icons on a page are clicked? The image of the icons can be found below: https://i.stack.imgur.com/mBC6o.png Here is the HTML code: <div class="slide overlay-container" id="int ...

What steps can be taken to ensure that an element is perfectly centered within a div?

I have a div containing some images: <div> <img src="1.png"> </img> <img src="1.png"> </img> </div> Currently, the layout in browsers looks like this: ----------------- |XX | ----------------- H ...

Verification of three-dimensional password format with the use of AngularJS

I am trying to implement password validation in Angular.js that requires a combination of alphabetical, numerical, one upper case letter, one special character, no spaces, and a minimum length of 8 characters. How can I achieve this using Angular.js? Here ...

Warning: Validation issue in console.js at line 213 - It is not valid for a <div> element to be nested inside a <p> element. Please correct this nesting validation

react-dom.development.js:86 Warning: validateDOMNesting(...): <p> cannot appear as a descendant of <p>. at p at http://localhost:5173/node_modules/.vite/deps/chunk-WQ5FBX7J.js?v=539aff10:2964:50 at Typography2 (http://localhost:5173/node_module ...

Manipulating anchor links with jQuery by adding and removing classes

I am struggling to understand why I cannot remove a class from an element and then add a new one. Changing the CSS using .css(...) works, but for some reason .removeClass and .addClass are not functioning. Interestingly, I am able to successfully add and ...

Swap an iframe for an image pulled from the iframe's URL using jQuery

My plan is to create a variable by extracting an attribute's value in order to add a new object using that variable as the value of another attribute... In my media search site, I am working with a restricted environment where I cannot fully configur ...

Overriding Styles Set by an External CSS file

Let's assume that I have two different style sheets set up on my webpage: site.css: .modal { position: absolute; width: 200px; ... } ... reset.css: .reset * { position: static; width: auto; ... } Unfortunately, I don ...

Empower your presentations with slick cloning technology

I am facing an issue with my slider that I cannot seem to resolve. Currently, I am using slick to display 3 slides, but only the center one shows all the content. To achieve a continuous infinite slider effect where all slides appear in the center, I need ...

Accessing the chosen value of an ng-model

Currently, I'm attempting to refine some search results by utilizing the chosen value from an ng-select element (stripping away unnecessary formatting and details). Here's what I have so far: <select ng-model="medium" ng-options="medium as me ...

When utilizing GET in PHP to handle data created using jQuery's $.param(data) function, you will come across %5B and %5D symbols being used

I am working with JSON data named rowdata that I utilize in an ajax call. When I use the following code: JSON.stringify(rowdata) The output looks like this: {"Description":"qwerty","Code":"12345","Size":"11","Colour":"green"} I am trying to send it to ...

Performing an AJAX request to a form within a CSS modal

Greetings from France, and please excuse any language errors in my English. I am currently coding in Symfony 3 and have an entity called "book" which can have different attributes (client, student, organizer, and/or speaker) based on the selected "type" a ...

Persistent column menu in ag-grid

Is there a way to include a menu for each row within a sticky column in Ag-grid? I couldn't find any information about this feature in the official documentation, so I'm unsure if it's even possible. I've attempted several methods, but ...