Automated scrolling effect within a container element

I am working on a div container named wrapper2 that houses a chat interface. Inside the container, there are five messages in a div called chatleft, each containing images. The height of the wrapper2 div is smaller than the combined height of all the messages.

This requires an automated animation based on time that scrolls the messages from top to bottom. For instance, when the page loads, after 5 seconds, the animation should begin and take 10 seconds to scroll down to the last message at the bottom.

Do I need to use JavaScript for this, or can it be achieved through CSS with timed animation? Could you assist me in creating this animation?

Below is the code snippet for the wrapper2 div:

#wrapper2 {
  

  margin: 0;
  padding: 40px;
  float: left;
  height: 740px;
  width: 600px;
  background-color: #fff;
  border-top: 7px solid #000CFF;
  border-left: 7px solid #000CFF;
  border-right: 7px solid #000CFF;
  bottom: 0px;
  background-image:

 url(https://cloud.githubusercontent.com/assets/398893/15136779/4e765036-1639-11e6-9201-67e728e86f39.jpg)
}

.chatleft:after {
content: '';
position: absolute;
left: 0;
top: 50%;
width: 0;
height: 0;
border: 24px solid transparent;
border-right-color: #ccc;
border-left: 0;
margin-top: -24px;
margin-left: -24px;
}

.chatleft:after {
content: '';
position: absolute;
left: 0;
top: 50%;
width: 0;
height: 0;
border: 24px solid transparent;
border-right-color: #ccc;
border-left: 0;
margin-top: -24px;
margin-left: -24px;
}
<div id="wrapper2">

</div>
<div class="chatleft">
  <p>Hi, <br> here's the text:
  </p>

</div>
<div class="chatleft">
  <img src="../bilder/smartwatch.png">

</div>
<div class="chatleft">
  <img src="../bilder/smartwatch.png">

</div>

<div class="chatleft">
  <img src="../bilder/smartwatch.png">

</div>

<div class="chatleft">
  <img src="../bilder/smartwatch.png">

</div>
</div>

Answer №1

Unfortunately, CSS alone may not be able to achieve your desired effect. I typically rely on JavaScript's scroll function instead.

element.scroll(x-coord, y-coord)

For more information, you can refer to the official documentation.

To accomplish what you're looking for, consider using this approach:

setTimeout(
  function(){
    // Perform actions, such as scrolling
  },
  [time in milliseconds]
)

Additionally, JQuery is a useful tool for handling animations:

$("html, body").animate({
  scrollTop: "500px"
});

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

Disabling an HTML attribute on a button prevents the ability to click on it

In my React application, I have a button component that looks like this: <button onClick={() =>alert('hi')} disabled={true}>test</button> When I removed the disabled attribute from the browser like so: <button disabled>test& ...

When there are spaces in the button, it will result in the button creating a new line within the Navbar

There is a line break in the navbar when a space is added to the button text The CSS for the Navbar is manually inputted (Utilizes Bootstrap) <img src="images/SCP_Logo.jpg" style='width: 100%; max-width:100%;'> & ...

Styling for older versions of Internet Explorer (IE10 and earlier)

Could it be true that IE 10, 9, and others no longer support conditional statements? Is it also accurate to say that JQuery does not support the browser object above version 1.9? I am facing an issue with CSS rendering differently in Chrome and IE. A Goog ...

Ways to identify whether a div is in view and includes an input field

This is a unique question that is not related to the issue of querySelectorAll detecting value in input. Instead of asking whether an input field has a value, I am interested in how to detect if the current visible div contains an input field. This is a n ...

PHP distributing empty sheets (possibly for website configuration)

Hey everyone! I've been struggling to set up a profile page on my website for the past week. Whenever I try to include PHP code or echoes in the content pages, I either get blank pages or encounter a 500 server error. My website is structured with a ...

Is there a way to dynamically add <td> based on the quantity of values in a JSON object?

I have developed a program that retrieves values from JSON and I aim to display these values in a table. Currently, only the last array value is being displayed in the table even though all values are available in the console. The objective now is to dynam ...

Could you advise on the best placement for my upcoming JQuery animation?

Here is the code I am currently working with: $(function() { $("button").click(function() { $("#box1").animate({ left: $(window).width() - 800 }, { complete: function() { $("#box1").hide(); } }); $("#box2").a ...

Using CSS to align the position of a div with the last word position of an h4 element

Trying to figure out how to position a div at the end of an h4 text element has been challenging. When the h4 text is on a single line, it's easy to place the div correctly. However, things get complicated when the text spans multiple lines. In that c ...

What is the best way to arrange the second div in the second row, while the first and third div are displayed on the first row within the MUI appbar

I have 3 components in the appbar, 1. Logo 2. Search Input 3. Login Buttons When viewing on desktop, all three components will be in a single row as shown below https://i.stack.imgur.com/FYMEH.png Below is my code snippet: export default function NavBar ...

A Guide on Adding Excel-Like Filtering Functionality to AngularJS

I am struggling to implement a simple Excel-like filter for a table using AngularJS (v.1). I have shared my code snippet below and would appreciate any help to show filtered data in the table after checking a checkbox and clicking on the OK button. I have ...

Verify if a checkbox is selected upon loading the page

Hey there, I have a jQuery change function set up to turn an input text box grey and read-only when a user selects a checkbox. However, I'm interested in adding a check on page load to see if the checkbox is already selected. Any suggestions for enhan ...

Issue with div in simple HTML code

I've been facing challenges with this line of HTML as I keep encountering errors and cannot pinpoint the source. The error highlight appears at the end of the last div, but once removed, another error emerges at the end of the body tag. Check out the ...

What is the best way to show the result of a PHP form in an HTML page when the PHP processing is on a different page, without relying

Imagine having a form located in the file called form.php. <form action="process.php" method="POST"> <input type="text" name="message"> <input type="submit" value="Submit"> </form> <span class="result"></span> The proc ...

The mask effect is not only darkening the background image but also affecting the color of my header content

Why is the mask I applied making not only my background image darker but also my h1 and button? <!-- Header - set the background image for the header in the line below--> <header class="bg-image d-flex justify-content-center al ...

Encountering overlap issues when applying labels to my flexbox using the Spectre framework in CSS

I need help creating a "hat" with two textarea columns using the spectre.css framework. My goal is to have these columns resize based on the screen size, stacking on top of each other when the screen size is below 600px. I can achieve this without any issu ...

"Place text at the center of a div that is rotated

I'm facing the challenge of centering a heading both vertically and horizontally within a div that has been rotated 45 degrees (transform:rotate(45deg);). Due to this rotation, I have attempted to counteract it by rotating the heading in the opposite ...

Variable fails to be assigned to Element

Having trouble updating the innerHTML attribute for both elements with ids containDiv and status. For some reason, it only changes containDiv but not status. The console shows an error "Cannot set property innerHTML of undefined", indicating that the eleme ...

Why isn't a single click enough to activate an anchor generated with the Sidr jQuery library in Rails?

I am utilizing a library named Sidr to generate sidebars. I have included all the necessary jQuery and CSS, and while it is operational, I find that I need to double click instead of just one click to open the sidebar. Here is the code snippet. I essentia ...

Turn off the ability to drag on an HTML page

Need help with creating an HTML etch-a-sketch! I have a div container with multiple div elements inside it, all set up with CSS grid display. HTML structure: <div id="canvas"></div> To populate the canvas with div elements, I'v ...

Exploring the possibilities of maximizing, minimizing, resizing, and creating a responsive design in dialog boxes using jQuery UI JavaScript and

I'm trying to create a dialog with maximize, resize, and minimize buttons like those found in Windows OS. I want the dialog to be responsive and draggable as well. I've been using jQuery, jQuery UI, and extended dialog frameworks, but I haven&apo ...