Using Jquery and CSS to create a sleek animation for opening a div box container

Designed an animation to reveal a div container box, but it did not meet the desired criteria.

Expectations:

  1. Initiate animation horizontally from 0% to 100%.
  2. Then expand vertically to 100% height.

The horizontal animation from 0% to 100% is not visible to users and the speed of the animation cannot be controlled effectively with this method. A slow and seamless animation is needed for better user experience.

Thank you!

HTML:

<div class="inactive" id="special-deals-animation">
  <div id="animation-container">
    <h3>Save up to 20% when you book in advance</h3>
    <p>Every savings of up to 20%</p>
    <a class="button button-primary text-center more-details" href="serviced-suites.html">More Details</a>
  </div>
</div>

JS:

$(window).scroll(function () {
    var scroll_pos = $(window).scrollTop() + $(window).height();
    var element_pos = component.offset().top + component.height();
    if (scroll_pos > element_pos) {
      component.removeClass('inactive');
      component.addClass('active');
      $('#animation-container').delay(600).fadeIn('fast');
    }
});

CSS:

#special-deals-animation {
  position: relative;
  width: 100%;
  background-color: #fff;
  height:auto;
  overflow :hidden;
  margin: 20px 0;
}

#animation-container {
  width: 50%;
  margin: 2% 25%;
  display: none;
  text-align: center;
}

#special-deals-animation.active {
  border: 1px solid #f00;
  width: 100%;
  transition: left 0.15s ease 0.15s, height 0.5s ease 0.5s;
  animation-iteration-count: 1;
}

#special-deals-animation.inactive {
  width: 0;
  height: 0;
  transition: left 0.15s ease 0.5s, height 0.5s ease;
  animation-iteration-count: 1;
}

Answer №1

Creating a simple animation effect like the one shown here is quite achievable:

html, body {
  height:100%;
  margin:0;
}

/* Ensuring html and body have "height:100%" */

div {
  height:100px;
  width: 100px;
  background: pink;
  animation:toright 2s linear forwards, tobottom 2s 2s linear forwards;
}

/* The second 2s defines an animation-delay for the first animation's duration */

@keyframes toright {
  to {
    width:100%;
  }
}

@keyframes tobottom {
  to {
    height:100%;
  }
}
<div></div>

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

What attribute should I utilize to ensure the image always takes priority over text when using @media queries?

resolution My goal is to have the image appear on top of the text when resizing the window, but maintain the appearance shown in the attached image when using a larger resolution. Below is the CSS code I am currently using: .section4 { text-align: cen ...

Looking to include some extra padding when an item is displayed - jQuery

So, I'm working on a jQuery code snippet that controls the visibility of a rectangle element: $("#rectangle").hide(); $("#toggle-rec").click(function () { $("#rectangle").toggle(2000); }); This code hides the rectangle initially and toggles it ...

Managing JSON data sent using PHP

After exploring numerous syntaxes from various sources on the internet, I am hesitant to reveal my struggles as it may be hard to distinguish fact from fiction. So... This snippet shows a part of my HTML code: var jsonData = { address: 'address& ...

Tips for launching a colorbox within a specific div container

I am looking to implement a color box that opens without a popup and only shows/hides inside a specific div. Is it possible to target a div to open the colorbox content? <a href='#myGallery' class='group'>click here</a> &l ...

For each JSON object, verify whether the value exceeds zero

How can I iterate through each Json result and check if any of the objects (Stage2) have a value greater than 0, then append it to a div? function service(){ var service_id=document.getElementById('down').value; $.ajax({ &a ...

Is it possible to use JavaScript to make a CSS animation mimic the behavior of a :hover effect?

My CSS animation looks like this: HTML: <div class="container" id="cont"> <div class="box show"></div> </div> CSS: .container { width: 100vw; height: 100vh; } .box { position: absolute ...

Tips for maintaining consistent width of a div:

My current project involves designing a website that displays various quotes, with each quote rotating for a specific amount of time. However, I'm facing an issue where upon loading the page, the first quote triggers the appearance of a scrollbar, mak ...

Error encountered while using Jquery's .each() method on a DOM element and attempting to

Trying to utilize the each() function on my DOM to dynamically retrieve a field, I encountered an issue with the following code: var new_entry = new Object(); $('div[name="declaration-line-entry"]').each(function () { new_entry.name = $(this ...

Error with the login component in React.js (codesandbox link included)

Hey there! I'm a beginner programmer and I recently dove into a tutorial on creating a Login Form. However, I've run into a few issues along the way. Overview of My Project: The login form I'm working on was built using create-react-app. T ...

HTML Scroll Blocking

Recently, I have been working on designing the mobile version of a website. However, I noticed that when I try to scroll quickly on my phone, the scrolling gets interrupted and I have to wait for it to catch up. I am using the fullpage.js library in this ...

When using HTML select, text alignment may not be centered properly in the Chrome

Recently, I encountered an issue where the text in select options is not centered in Chrome. Interestingly, using text-align: center on the select element works perfectly fine on Firefox, but fails to do so on Chrome. I haven't had the chance to test ...

"How to dynamically fill a text input field from a table using jQuery when a specific value is selected, potentially involving multiple rows (possibly

Scenario I created a form that allows users to place orders for articles. These articles are displayed in a table within another form, where each article is listed with its code, description, and price. The goal is for users to select an article from th ...

CSS does not alter the properties of a link's "background-color" or "border-color"

I have successfully changed the text color of visited links, but I am struggling to change the "background-color" and "border-color" properties. The initial part of my internal style sheet includes a CSS reset. a:visited { color: red; background-col ...

Tips for adjusting the color of a row when hovering

Can I modify the row color on hover in material-table using props? Similar to this example. Appreciate your help. ...

Converting jQuery MouseWheel Event into Pinch Event

I'm in the process of converting my project to a Cordova application, but I've hit a roadblock with the mousewheel event. Does anyone know what the equivalent event is in Cordova? Currently, I have a canvas with some objects on it that I zoom in ...

"Internet Explorer: Unleashing the Magic of Card Fl

I'm encountering a problem that I can't seem to solve. Everything works perfectly in Chrome, FF, Safari, etc., but in Internet Explorer, I see the image on the front side instead of the text on the backside. Can anyone please assist me with this ...

Transforming a string into an object

I've been working on this code where my aim is to convert a string into an object and then display the data from an ajax call. However, it appears that using the string value in this way is not functioning as expected. var string = "first: 'Geor ...

Combine several arrays together and return a new array with only unique elements using jQuery

I am encountering an issue with isotopes. When loading elements using ajax, the new elements include classes that are also utilized in filters. To retrieve all the classes from the elements, I have implemented a method of checking if the elements are with ...

Navigate to the middle of a DIV container in Angular 7

Is there a way to programmatically scroll to the center of my element on both the Y and X axes when a specific function is executed? My HTML structure includes the following (I am aiming to scroll to the middle of #viewport): </div> <div # ...

create new Exception( "Invalid syntax, expression not recognized: " msg );

Can someone assist me in identifying the issue at hand? Error: There seems to be a syntax error, and the expression #save_property_#{result.id} is unrecognized. throw new Error( "Syntax error, unrecognized expression: " msg ); Here is the c ...