Is there a way to automatically scroll two identical vertical long images one after the other in a continuous loop?

My goal is to replicate the effect seen on the website , where a vertical image moves downwards and then repeats by starting from the bottom once it reaches the top. Essentially, there are two images moving downward in this loop.

I attempted to find a suitable npm library to achieve this effect but unfortunately was unsuccessful.

Answer №1

The website utilizes a method similar to a requestAnimationFrame() loop to adjust the transform css property of an image using translateY(N%).

let direction = 1;
(function scroll(percent) {
  // reducing the speed value slows down the scrolling
  const speed = 0.25;
  
  // manipulate the passed value, starting from 0 and moving towards -100
  percent -= direction * speed;

  // update the style property
  example.style.transform = `translateY(${percent}%)`;

  // reverse the direction when reaching 0 or -100
  if (percent <= -100 || percent >= 0)
    direction *= -1;

  requestAnimationFrame(() => scroll(percent));
})(0)
body {
  position: relative;
  overflow: hidden;
  max-width: 100vw;
}

img {
  max-width: 100%;
  position: absolute;
}
<img id="example" src="https://i.imgur.com/zVQzmPI.png">

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

Steps for removing the ag-grid-community software from your system

I need assistance removing the ag-grid-community package from my React project. Despite attempting multiple npm uninstall commands, such as npm uninstall -g --force --save ag-grid-community, the package remains in both node_modules and package.json. The ...

Extracting CSS data and storing it in a SQL database

Hello there, I've created a div using CSS like this: echo '#'. $pess2['naam'] .' { width: 190px; height: 90px; padding: 0.5em; float: left; left:'. $pess2['left'] .'px; top:'. $pess2['top'] ...

Why is my image being stretched by flexbox instead of maintaining its aspect ratio?

One interesting aspect of Flexbox is how it handles image resizing. When you resize the width of an image within a flex container, the height does not adjust proportionally. This causes the image to appear stretched. div { display: flex; flex-wrap: ...

implementing a button's decrease and increase functionality in JavaScript

Whenever the button is clicked, it changes its color to red. Additionally, a counter increments with each click. However, I want the counter to be dynamic so that when the button is unclicked, the counter decreases as well. Unfortunately, I am facing diffi ...

I'm having trouble getting my text values to line up next to my slider bar

I've been troubleshooting this issue for a couple of hours now. (My CSS skills are not the best) Currently, I have two jQuery sliders with values. My goal is to position "Rooms: 0" and "Bathrooms: 0" right next to their respective slider bars. . ...

Tips for modifying fullcalendar's renderEvents handler to include custom code

Currently, I am working with fullcalendar 1.6.3 in conjunction with Drupal 7 (which is why I have to stick with version 1.6.3 for now). Every time the calendar view changes through ajax requests - whether moving forward or backward in time or switching bet ...

Error encountered: During npm install process, the application exited unexpectedly due to a lifecycle issue with code EL

I keep encountering an error every time I try to run npm install on my boilerplate project: ERROR in multi react-color moment ag-grid ag-grid-react es6-promise react-dom-factories react-spinners sortablejs Module not found: Error: Can't resolve &apos ...

Backend data not displaying on HTML page

I am currently working on an Angular 8 application where I have a service dedicated to fetching courses from an API endpoint. The service method that I'm using looks like this: loadCourseById(courseId: number) { return this.http.get<Cours ...

I'm currently troubleshooting the code for the Gallery project. The gallery is supposed to have 4x4 grids, but for some reason, the grids are

It seems like I am struggling to identify the exact issue. The display on mobile looks fine but not on desktop. I attempted to tweak the isotope configuration without success. Even manipulating the server-side code didn't reveal any obvious problems. ...

Trouble in Dockerland: Struggling to Connect to the Database

Today, I encountered an error on my Mac 14.2.1 with Docker 4.27.2. When running npm run wp-env start, the container is created and running, but a database connection issue is displayed. ➜ TEST npm run wp-env start > @ wp-env /Users/ciaran/Projects/T ...

Struggling to make vue-i18n function properly with nuxt generate?

In an effort to enhance my skills, I am creating a small Nuxt project from scratch. While the project runs smoothly on the local server, I have encountered an issue with the language switcher not updating the translation fields when using nuxt generate. U ...

The JSColor onChange event is throwing an error indicating that the function is not defined

When attempting to use the onChange event for JSColor to call a function, I consistently encounter an error indicating that the function is not defined. The code snippet below illustrates the issue: export class NavBar extends React.Component { constr ...

Nodejs: Dealing with Regex Errors

I am encountering an issue with my CORS configuration code in NodeJS. Here is the code snippet: var allowedOrigin = new RegExp('^https?://(' + config.get('http:allowedOrigins').join('|') + ')(:\\d+)?(/.*)?$&apo ...

How can I show an item repeatedly with each button click in ReactJS?

Currently, I have a setup where I can display a checkbox and its label upon clicking a button. However, the limitation is that only one checkbox can be displayed at a time. Is there a way to modify this so that I can show multiple checkboxes simultaneous ...

Chrome displaying elements out of alignment

Anyone have any insights into why my webpage elements are displaying differently in Chrome compared to IE? It's driving me crazy! Here's a screenshot of how it looks in Chrome: https://i.sstatic.net/xAlEi.jpg And here's how it appears in IE ...

Endless cycle of changing border colors

I'm trying to achieve a specific effect where the border of a div changes colors in an infinite loop. However, I want this effect to be applied only to the border of the div and not the entire body background. Here is an example: http://jsfiddle.net/A ...

Disabling the intellisense feature for locale suggestions in Monaco is recommended

Switch the keyboard language to a different one (in this case Japanese using alt + shift), and when typing in Monaco editor, an intellisense menu appears with options to remove and search. Monaco Editor Version: V0.33.0 https://i.stack.imgur.com/SIyeV.pn ...

What is preventing me from binding the array index to a model in AngularJS with two-way binding?

I'm currently facing a challenge with a seemingly simple task: I have an array of string values that I want to link to a select element's options, and then connect the index of the chosen value to a variable. However, I have found that neither us ...

Using Vue-router and Typescript with beforeEnter guard - utilizing validated data techniques

As I utilize Vue along with vue-router and typescript, a common scenario arises where a single page is dedicated to displaying a Photo component. A route includes a beforeEnter guard that checks my store to verify the existence of the requested photo. ...

Nginx forwards static content to a subdirectory within the main root directory

I have an application running at http://192.168.0.2:8080/. The main index.html page is located in the /web directory and it fetches static files, such as css, from the /css folder. My aim is to use nginx as a reverse proxy to redirect myapp.mydomain.com t ...