The background image does not appear on the animated div until the browser window is resized

Encountering an unusual problem - I have styled a div element using CSS to be initially hidden:

 .thediv {
  width: 100%;
  height: 87%;
  position: fixed;
  overflow: hidden;
  background-image: url(pics/FrameWithBG1280.png);
  background-attachment: fixed;
  background-size: 95% 87%;
  -webkit-background-size: 95% 87%;
  -moz-background-size: 95% 87%;
  -o-background-size: 95% 87%;
  background-repeat: no-repeat;
  background-position: center 84%;
  color: white;
  padding-left: 100px;
  padding-top: 50px;
  top: -110%;
}

To reveal it, I use a button click event:

$('.thebutton').click(function(){ 
   $('.thediv').animate({top:'11%'})
});  

Everything works as expected, except that the background image doesn't display until I manually resize the browser window. This issue occurred consistently across Chrome, Mozilla, Opera, and Edge browsers.

Any insights on why this behavior might be occurring?

Answer №1

The idea of the relative must always stem from the foundation of the absolute.

Within your coding structure, all values are defined in terms of percentages. However, upon resizing, the script will incorporate absolute units (such as pixels) to this block or its parent elements. This adjustment allows the percentages to function properly and impact the image accordingly!

A possible resolution is to introduce absolute unit values to the block or its ancestor elements. Additionally, utilizing vh and vw can help establish a connection with the dimensions of the browser viewport.

You cannot extract substance from nothingness, uncertainty, or boundlessness.

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

:Incorporating active hyperlinks through javascript

Hey there, I've encountered a little conundrum. I have a header.php file that contains all the header information - navigation and logo. It's super convenient because I can include this file on all my pages where needed, making editing a breeze. ...

Modify the database value linked to an <input> element each time its value is modified

I attempted to create something similar to the example provided here $(document).ready(function(){ $('input[type=text]').keyup(function(){ var c=0; var a=$(this).attr('name'); //a is string //if var a change.. ...

Using jQuery: How can we manipulate the data returned by sortable('serialize') on a list?

Using jQuery, I have successfully retrieved the positions of a sortable list by using 'serialize' as shown below: var order = $('ul').sortable('serialize'); The variable 'order' now contains this data: id[]=2& ...

The input field will be in a read-only state if it contains a value from the database. However, it will be editable if the value

Hello everyone, I am a newcomer to this community and would greatly appreciate your help. I am encountering an issue with the following lines of code: <input type="text" class="form-control" id="fines" name="fines&quo ...

What's the best way to perfectly align table text in the center both horizontally and vertically?

Despite encountering similar or potentially identical questions, I have attempted the suggested solutions without success. My aim is to design a table that centers text both vertically and horizontally, ideally using flex. However, the structure of the ta ...

Jquery's intermittent firing of .ajax within if statement

So, I've inherited a rather messy codebase that I need to modernize. The task involves upgrading from an old version of prototype to the latest jQuery 3.2.1 within a dated website built on php and smarty templates (not exactly my favorite). When a lo ...

Converting a jQuery/JSON/PHP object to a C# function

Hello everyone, I am new to JSON and I recently came across an example that uses PHP and jQuery (http://wil-linssen.com/entry/extending-the-jquery-sortable-with-ajax-mysql/). My goal is to take the serialized "order" object and utilize it in a C# method j ...

Illustrate an element positioned beneath a child element within a different element

I am in the process of designing an overlay on a Google Map that resembles a real map placed on a table, using 2 pixel lines as creases above the map. This design does not significantly impact interactions with the map; only 6 out of 500 vertical lines are ...

Animating object on display and returning it with keyframes

Given the code snippet below: <div class="leftBox"> <div class="mainNode" ></div> </div> <script type="text/javascript"> $('.mainNode').click(function() { var element = $('.mainNode'); if (!ele ...

Generate a new cookie only when it is not currently present

My objective is to: Determine if a cookie named "query" exists If it does, take no action If not, create a cookie called "query" with a value of 1 Please note: I am working with jQuery version 1.4.2 and utilizing the jQuery cookie plugin. Any recommend ...

Utilizing ellipses within a list item to create a visually appealing design

I've been struggling with this problem for hours, but I can't seem to find a solution. How can I ensure that the text in a list item respects the size of its parent container and uses an ellipsis when necessary? Here's the scenario: <?P ...

Steps to deactivate a JavaScript function once the page has undergone a Page.IsPostBack event

My current setup involves a simple div with the display set to none. Upon page load, I use $("#MyDiv").show(); to display the div after a delay, allowing users to enter information into the form and submit it using an asp.net button. After submitting the ...

What methods can I use to display or conceal certain content based on the user's location?

I'm looking to display specific content exclusively to local users. While there are APIs available for this purpose, I'm not sure how to implement them. I'm interested in creating a feature similar to Google Ads, where ads are tailored base ...

What steps can be taken to enlarge the select button within a <select> field?

Is there a way to enlarge the size of the downward-pointing arrow button within a <select> element? Here is an example of what my code looks like: <select> <option>Select City</option> <option>City1</option> <o ...

Step-by-step guide to implementing a month and year date-picker in Mozilla Firefox

I'm looking to create input fields where users can add the month and year. I tried using the code below, but unfortunately Mozilla Firefox doesn't support it. <input type="month" id="start" name="start"> Does ...

Is jQuery the solution for tidying up messy HTML code?

Is there a way to clean up this markup using jQuery? <span style="font-size:19px"> <span style="font-size:20px"> <span style="font-size:21px"> Something </span> </span> </span> I'm looking to tra ...

What causes "this" to exhibit distinct behavior from the selected name?

Although I'm still getting the hang of using jquery, I've been experimenting with it for a few weeks now. So please bear with me if my question seems basic to you. Recently, I put together a jquery script that seems to be working well. <scri ...

Java displays misaligned text vertically

In my attempt to implement word-wrap for my JLabel's text, I referred to this question. The code snippet I used for this purpose is as follows: label.setText("<html style=\"vertical-align:middle;\">"+label.getText()+"</html>"); ...

Achieving distinct CSS margins for mobile and desktop devices in a Django template without the need for multiple {% block content %} statements

Is there a way to dynamically change the margin-left of my main {% block content %} in the base.html template based on whether the viewer is using a mobile or desktop device? This is how my current base.html looks like: <div class="content container-f ...

Photographs featuring a ripple effect in the columns of Zurb's Foundation framework

Working on a WordPress site using the Foundation 6 CSS framework, I have a design with a row containing two large-6 columns, each filled with an image featuring a wave shape. Check out the image I've linked below. View the row with 2 columns I' ...