div maintain aspect ratio while scaling

My current layout is structured like this:

HTML

<div id="container">
    <div id="zoomBox">
        <div class="box"></div>
        <div class="box"></div>
        <div class="box"></div>
    </div>
</div>

CSS

#container { width:100%; }
#box { height:1000px;width:920px; }

I am currently using the transform: scale() property to preserve the aspect ratio of my container and its contents. However, I am facing compatibility issues with Internet Explorer. Any suggestions on how to make this work smoothly on IE?

This is a snippet of my JavaScript code for scaling:

function zoomProject(percent)
{
    $maxWidth = $("#container").width();

    if(percent == 0)
        percent = $maxWidth/920;

    $("#zoomBox").css({
        'transform': 'scale(' + percent + ')',
        '-moz-transform': 'scale(' + percent + ')',
        '-webkit-transform': 'scale(' + percent + ')',
        '-ms-transform': 'scale(' + percent + ')'
    });
}

Answer №1

For those without jquery set up, here's an example using raw HTML and JavaScript. Please note that this may not function correctly on older versions of Internet Explorer due to syntax differences, but after switching it over to jQuery, it should work fine.

Here is the code snippet:

function zoomProject(ratio) {
  var i, height;
  var boxes = document.getElementsByClassName("box");

  for (i=0;i<boxes.length;i++) {
    height = (boxes[i].offsetWidth * ratio) + "px";
    boxes[i].style.height = height;
  }
}

zoomProject(.1);

.container { background: red; width: 100%; height: 100%; }
.box { background: blue; width: 100%; border: 1px solid white;}

Answer №2

Experiment with no transformation:

updated_width = width * percentage / 100;
updated_height = height * percentage / 100;
$("#zoomBox").css('width', updated_width);
$("#zoomBox").css('height', updated_height);

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

Show a 1920x1170 / 183KB image as the background using CSS styling

I need help with displaying a background image that is 1920x1170 pixels and has a file size of 183KB. Here is the code I am using: .bground{ height:auto; left:0; position:fixed; top:0; width:100%; } <div class="bgrou ...

Including Parameters in File Paths with ExpressJS

I am currently facing an issue with uploading specific photos to a client's folder within my public/assets directory. The file path I am aiming for is public/assets/:id. However, when running my code, the file path always ends up being public/assets/u ...

Leveraging onclick in ng-repeat

Can the onclick event be used within a ng-repeat to call a jQuery function? HTML: <table> <tr ng-repeat="item in items"> <td><a onclick="loadEditModal(item.Id)">Edit</a></td> </tr> </table> ...

The Evolution of Alternatives to contentEditable

Related: ContentEditable Alternative I am curious about the timeline of online WYSIWYG editors prior to the existence of contentEditable. I remember using GDocs and GMail with rich-text features that functioned similarly to contentEditable. I would appre ...

What is causing the table to not be displayed in this Javascript program when it is used in a

I am currently experimenting with incorporating an infinite loop before the prodNum and quantity prompts to consistently accept user input and display the output in a table. Although the program is functional when executed, it fails to showcase the table ...

reverting the effects of a javascript animation

I am expanding the size of a carousel on a specific pane by adjusting its height and position. Here is how I achieve this: if(currentPane==2) { $("#carousel").animate({height:320},1000); $("#carousel").animate({top:411},1000); $("#dropShadow") ...

Developing a dynamic master-details view on a single page with ASP.NET MVC

This is a question related to design and technology. When using ASP.NET MVC, it is possible to create a simple application with two views: one master view that displays all records in tabular form in read-only mode, and another details view for creating n ...

Send a webhook post request without causing a redirection

Is there a way to send a post request to a webhook without redirecting the user directly to the webhook URL, after validating their input? ...

What steps should I take to show a particular set of data upon selecting a checkbox component?

I have a table with a column named status, which can be in progress, pending, or dispensed. My goal is to filter the data based on the checkbox that is selected above the table. For instance, if I check the "pending" checkbox, only the data with the pendi ...

Unable to concatenate values from Object in JavaScript

Although it may seem trivial, the following code is giving me trouble: window.temp1.targetInterests It gives me back: Object {Famosos: "Famosos", Musica: "Música", Humor: "Humor"} I attempted to join it: window.temp1.targetInterests.join('/&apos ...

How can I toggle the visibility of an accordion panel using Jquery when clicking the "edit" button within a gridview

Is there a way to toggle an accordion panel based on the row clicked in an ASP.NET GridView? I have a jQuery Accordion above the GridView and would like to show/hide specific panels when clicking the edit button. Can this be achieved within the GridView_ ...

Setting the title of a document in Angular 5 using HTML escaped characters

It seems like a simple problem, but I can't seem to find an easy solution. Currently, I am using the Title service to add titles to my documents and everything is working fine. You can check out the documentation here: https://angular.io/guide/set-doc ...

Prevent scrolling in a full-screen modal using CSS

I came across a beautiful fullscreen modal that is purely based on CSS. The only issue I encountered was that the modal isn't scrollable. I attempted various solutions but haven't been successful. Here's the script I am using: ...

Looking to turn off animation for a WordPress theme element?

Is there a code that I can insert into the style.css file to deactivate the theme animations on my WordPress page? As users scroll down, each element either drops in or slides in. I recently purchased the WP Alchemy theme from , but the animation speed is ...

Using Angular 10 to make an HTTP POST request, with the goal of appending a string

Whenever I try to send a post request to an api endpoint, I keep encountering an error with status code 500. name: "HttpErrorResponse" ok: false status: 500 statusText: "Internal Server Error" Below is the code I am using: var selected ...

Embed a data entry point into an existing picture

Looking for assistance inserting a field within an image for users to enter their email. Can someone provide the HTML code for this? Appreciate your help! ...

When placed within a setInterval loop, the event.clientY variable becomes inaccessible

I am working on a script to move an element around a web page, and I have encountered a problem. Whenever I try to put it in a loop using setInterval while the mouse is down and moving, I receive an error message stating 'Uncaught TypeError: Cannot re ...

When making an Ajax request, the response is received successfully, however, the success, complete, and error

I am attempting to retrieve SQL results from a database using an AJAX call and display them on another PHP page. Here is my AJAX call code: function newfunc(){ start += 10; var params = parseURLParams(document.URL); var datastring = "nextStart="+start+"&a ...

Transfer the data from a post request through routes following the MVC pattern

Encountering an issue when attempting to submit a post form with username and password, as an error stating Cannot POST /validateUser is displayed. The structure of my form is as follows: <!DOCTYPE html> <html> <head> <title> ...

Why is it that my terminal doesn't close after my gulp process completes?

I am looking to implement React in my NodeJs application. Here is the content of my gulpfile: let gulp = require('gulp'); let uglify = require('gulp-uglify'); let browserify = require('browserify'); let babelify = require(& ...