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

Parsing XML using jQuery AJAX without the need for the find method

I have been experimenting with implementing ajax in our webservices to optimize the loading speed of certain pages. I have managed to create a working sample, but I am looking for a way to make this process more efficient for use across multiple pages with ...

What is the best way to align Bootstrap icons in the middle of buttons?

Currently, I am incorporating bootstrap icons into my design. Feel free to explore the provided DEMO. It showcases the issue of the bootstrap icons not aligning in the same line as the text inside the button. I am seeking advice on how to centralize the i ...

Dynamic columns added to the DataTables plugin with the use of the brackets-negative feature

Before initializing my DataTable, I dynamically generate headers for it. As a result, I am unable to predict the column datatypes, relying on DataTables to identify them based on the data for sorting. Some columns contain currency data in formats like $23 ...

The load() function is experiencing issues with executing scripts

I have a script on the page where I want to load the file: <SCRIPT type="text/javascript"> $(function() { $("#storefront").click(function () { alert("POTANGINA"); $(".centerdiv").load("storefront_a.php"); ...

Guide to retrieving a user's current address in JSON format using Google API Key integrated into a CDN link

Setting the user's current location on my website has been a challenge. Using Java Script to obtain the geographical coordinates (longitude and latitude) was successful, but converting them into an address format proved tricky. My solution involved le ...

Tips for vertically centering text within a panel using Bootstrap 3

I am facing an issue where I have an image and a description inside a panel panel-default. The image is floated to the left while the description is on the right side. The image has the img-responsive class so that it adjusts according to the panel body w ...

Retrieve JSON data from a PHP script

Hey there everyone, I'm new to working with JSON and I need some help. I have data (an array) that was sent from a PHP file in encoded format, and all I want to do is simply get this data and display an alert with it. The object sent from the PHP fi ...

Is it necessary for the URL of Ajax's $.post function to be identical to the URL specified in the web

I need to transfer data from my JavaScript code to a servlet. My JavaScript file is located in the webapp\secure folder, while the servlet is in the java\com\servlet folder. After researching, I found out that I can use AJAX to send data. T ...

When displaying content within an iframe, toggle the visibility of div elements

I'm attempting to toggle the visibility of certain page elements based on whether the page is loaded in an iframe. <script>this.top.location !== this.location && (this.top.location = this.location);</script> The above code succes ...

Styling with CSS: Enhancing list items with separators

Is there a way to include a separator image in my list using CSS? li { list-style: none; background-image: url("SlicingImage/button_unselect.png"); height: 53px; width: 180px; } This is the code for the separator image: url("SlicingImage ...

What is the best way to prioritize loading a specific div on a website before anything else?

On my website, I have two div panels: left_panel and right_panel. The left panel contains hundreds of food items, while the right panel displays a small box for orders where users can see how many items they have added from the left panel. The issue aris ...

I'm curious if it is possible to retrieve the dates of actions on websites using Selenium with Python

Is there a way to retrieve the date of data, like the date of comments, using HTML codes? I need assistance on how to achieve this through selenium in Python. Can Jquery be used as a solution? ...

Transmitting and receiving a blob using JavaScript

Is there a way to send a blob using a JQuery ajax request and receive it server-side with Node.js + express? I tried sending the blob as a JSON string, but it doesn't seem to include any of the binary data: {"type":"audio/wav","size":344108} Are th ...

How can I resolve the issue of <td> being repeatedly displayed five times instead of just twice in PHP?

Can someone assist me with fixing this for loop issue? I am trying to display controls next to each item in the row, but it is showing 5 sets of controls instead of just 2. <tbody> <?php //retrieve list of supplies $numOfRows = 0; $result = my ...

Combining PHP JQuery Dialog with Datatables results in a sleek design loss

Recently, I encountered an issue with my code. I have a file called incident_view.php which pulls data from the database and displays it using Datatables. Everything was working fine until I tried to open this page in a JQuery dialog on another page called ...

An automated feature that smoothly transitions a large image onto the screen

I came across a plugin, possibly a slideshow plugin, that smoothly slides a large image along the y-axis. It's hard to explain, but imagine the visible image is only 600px by 300px, while the actual image is 600px by 600px. This plugin would scroll t ...

What are the steps to update content by referencing an id in the hash URL?

Currently, I am utilizing the following code snippet to extract an ID from the hash URL: var integer = window.location.hash.match(/\d+/) | 0; alert(integer); However, I have encountered an issue where upon using the back button after modifying the U ...

The paragraph tag closes automatically once opened

In the process of establishing a news section on my website, I encountered an issue while using the following code: <p id="news-container"> <h1> . . . </h1> <strong>big</strong> . . . </p> Upon inspecting, it appea ...

How do I modify the sidebar width with CSS code?

I am trying to adjust the width of the right sidebar on my website. The current layout leaves too much empty space on the right side and makes it appear crowded next to the main content and images in the center. Despite exploring various solutions provide ...

Displaying dropdown options based on the previous selection made by the user

Can I link the data in my second dropdown to the selection made in the first dropdown? I tried a similar solution from stackoverflow without success. You can find the reference here. The code works when directly copied and pasted but not within my system. ...