Adjust the size of a container while maintaining a consistent aspect ratio

In my jQuery code, I created a div with a width of 100% and a height equal to the width multiplied by 0.1.

http://jsfiddle.net/2drYk/

<figure class="container">
</figure>

$('.container').height($(this).width() * 0.1);

* 
{
    margin:0; 
    padding:0; 
    border:0;
}

.container
{
    width:100%;
    background:black;
}

I am now wondering how I can expand the height when clicking on this element.

Answer №1

$('.block').height($(this).width()*0.1);

$('.block').on('click',function(){
    $(this).animate({height: ($(this).width()*0.1 + $(this).height())});
});

check out the demonstration JSFIDDLE

Answer №2

.wrapper
{
    width:100%;
    background:black;
    transition:all 500ms;
    -webkit-transition:all 500ms;
    -o-transition:all 500ms;
}

.wrapper.adjustedHeight{height:500px}

$('.wrapper').on('click',function(){
   $(this).toggleClass('adjustedHeight');
});

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

Automatically clear select2 inputs after form submission in Laravel using Livewire

How can I set my barcode scanner to automatically select and clear the search box upon submission? <script> $(document).ready(function() { $('.js-example-basic-single1').select2(); $('.js-example-basic-single1&ap ...

Bootstrap - Border padding excessively wide

For a project exercise using bootstrap, I'm working on recreating a page that can be found here: https://codepen.io/freeCodeCamp/full/NNvBQW I've hit a roadblock in trying to put a border around the image. Here's the code I have so far: htt ...

The excess triggering of ajax events is occurring due to the else clause

My website contains an ajax function that calls a cgi script. Occasionally, this script returns a 500 error. I want to modify the AJAX call so that it retries the request when this error occurs. Here is how I have attempted to do so: function shelverx() { ...

Send JavaScript variable using a query parameter

I am working on passing a JavaScript variable across all pages in my project. The goal is to calculate the total value from various pages and display it at the end of navigation. Below is an example of my JS code: <script> $(document).ready ...

JTextPane Highlighting Issues: Offsets Not Aligned Properly

Working on a Text Editor project in Java that incorporates Syntax Highlighting with JTextPane. Upon running the program, encountering unexpected output at: The aim is to highlight all HTML tags in pink color, however, the highlighting seems to be inaccura ...

Creating a responsive DataTable filled from a $.ajax request is a straightforward process that can greatly

I am in the process of creating an application that retrieves a lot of data from a web-service query and populates a data table with it. The data shows up correctly and styled properly on desktop, but when I switch to viewing it on a mobile device, the dat ...

What is the best way to align text above a wrapper box?

After watching a tutorial on YouTube about creating a simple login form, I decided to customize it with some personal touches. I wanted to include a "Welcome" text above the login form, but when using h1, the text appeared next to the box rather than abov ...

Guaranteeing the sequential execution of JavaScript functions

For weeks, I've been struggling with a program that utilizes ajax post methods and dataTables. It has become clear to me that my understanding of how javascript operates is lacking. Below is the javascript code: $('#SaveTimeSheet').click(fu ...

Changing Scroll-bar Colors in JavaFX TableView Using Java

I modified the style of my TableViews programmatically with the following code- tableView.setStyle("-fx-base : #333333; -fx-background-color : gray"); Now I am looking to change the color of the scroll bar using the same method. I prefer not to add a ...

Revamping the appearance of Youtube's DOM elements to enhance user experience

Each Youtube video includes a column div with two children: primary and secondary. https://i.sstatic.net/c4ayc.png https://i.sstatic.net/8bFf3.png The primary div contains a 'ytd-comments' element which houses all comments. I attempted to move ...

Is there a way to reach a label within a <td> element in a repeater from another <td> element within the same repeater?

I am struggling to access the text of a label in a repeater from another part of the code. <asp:Repeater runat="server" ID="Repeater1"> <ItemTemplate> <tr role="row" class="odd"> <td><asp:Label ID="Label1 ...

Search on the server side using AJAX, allow users to finish entering text before displaying results from multiple

Below is the code snippet I am working with: $('.gerais').each(function(){ var daotable = $(this).data('dao'); x = $(this).DataTable({ serverSide: true, ajax: { url: $('body').data('ur ...

When the oncuechange event is triggered, it initiates a smooth fade-in/fade-out animation within the HTML P tag

Just starting out with web development and learning JavaScript. Trying to create a webpage that displays lyrics synced with an audio file inside a p tag. The subtitles are sourced from a vet file extension and I am using the "cuechange" event in JavaScript ...

A guide on incorporating text into a file utilizing JSP within HTML

I am working on a project that includes a JSP file and a .txt file. The JSP file contains a text field and a button, where the user can enter a text and click the button to store it in the .txt file. I have provided my code below, but I seem to be missin ...

Creating a horizontal layout for list items that are responsive using CSS

My website has a "Featured" section with 3 equally sized elements displayed horizontally. I want to make the webpage responsive by using percentage widths, but when I resize the window to less than the list width, the items stack on top of each other. Che ...

The execution of the selenium script is unreliable

Recently, I created a selenium script to automate certain manual checks on http:obsessory.com. The script utilizes a looping concept, such as mouse hovering over the Top menu and clicking on various submenus. However, during testing, I have encountered spo ...

Clicking on a specific month results in displaying only one row from the database rather than showing all rows associated with that particular month

I am facing an issue with my calendar feature on the website. The problem is that when I click on a specific month, it should display all the data associated with that particular month. However, the current code does not seem to work as expected. For insta ...

Dropdownmenu without borders

I'm having an issue with the dropdown menu on my website - there are no borders showing. I've tried fixing it myself with no luck, so I could really use some help. As a beginner in web development, I don't have much knowledge about these thi ...

CSS button pressed

I came across a helpful discussion on the topic of CSS for pressed buttons, which provided some answers that I found useful. The link to the discussion can be found here: Pressed <button> CSS. Currently, I have a button within a link and I would lik ...

Initial size of a div element with relative positioning

When a div tag has an absolute position, its height and width default to 0. In contrast, when it has a relative position, the default width is set to 300px. I am looking for a way to have a div tag with a width of 0 and a relative position... ...