Guide to creating scroll-based animations for a Div element

I've been brainstorming ways to rotate a div as I scroll. My goal is to recreate the effect shown in this codepen.

However, I'm struggling to implement scrolling functionality. What I envision is scrolling down causing the word Data to rotate in a counter-clockwise direction. Additionally, I want the rotation speed to be synchronized with the scrolling movement, limiting it to 90deg either up or down. Any pointers would be greatly appreciated!

var btn = document.querySelector('.button');
var btnUp = document.querySelector('.button-up')

btnUp.addEventListener('click', function() {
  document.querySelector(".parent").style.webkitTransform = "rotate(-90deg)";
  document.querySelector(".child").style.webkitTransform = "rotate(90deg)";
});

btn.addEventListener('click', function() {
  document.querySelector(".parent").style.webkitTransform = "rotate(0deg)";
  document.querySelector(".child").style.webkitTransform = "rotate(0deg)";
});
.parent {
  position: relative;
  width: 300px;
  height: 300px;
  border-radius: 50%;
  transform: rotate(-0deg);
  transition: transform 0.7s linear;
  margin: 100px auto 30px auto;
}

.child {
  position: absolute;
  transform: rotate(-0deg);
  transition: transform 0.7s linear;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  text-align: center;
  top: 278px;
  /* -child size/2 */
  left: 130px;
  /* parent size/2 - child size/2 */
}
<div class="parent">
  <div class="child">
    Data
  </div>
</div>

<button class="button">Click Down</button>
<button class="button-up">Click Up</button>

Answer №1

Include the following code in your project:

<link href="https://unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="17767864572539243926">[email protected]</a>/dist/aos.css" rel="stylesheet">
<script src="https://unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="92f3fde1d2a0bca1bca3">[email protected]</a>/dist/aos.js"></script>

Next, include this script:

<script>
  AOS.init();
</script>

Then, designate an element with animation effects:

<div data-aos="fade-down"></div> //you can use any desired effect

For more guidance, refer to:

this helpful website

Additionally, visit AOS Animation for further information.

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

Tips for seamlessly incorporating WalletConnect into your decentralized app with the help of web3-react

I have been working on integrating WalletConnect into my project by referring to the documentation provided by web3-react. The configuration settings I am using for the connector are as follows: import { WalletConnectConnector } from '@web3-react/wal ...

Mastering the fundamentals of integrating/augmenting a fresh template in Umbraco

Let me be completely honest. Umbraco is unlike any other CMS I have worked with before. I am currently struggling to grasp the proper method of creating a Template and integrating it into Umbraco. How exactly can I add a template? I am making changes to t ...

Tips for effectively managing the timeout of server-side AJAX calls1. Maxim

I'm currently developing server code in ASP.NET with the MVC framework. The client-side code is written in javascript. When sending an AJAX request from the browser to the server, whether using JQuery or not, timeouts can be set. Additionally, the br ...

What are the steps for creating a simple .htaccess file to add password protection to a website?

To enhance the security of my website, I implemented protection measures by creating a .htaccess file within the directory /var/www/html/. AuthType Basic AuthName "One does not simply" AuthUserFile /home/user/.htpasswd Require valid-user Additionally, I ...

Create unique list markers by utilizing the "::marker" and "content" properties

When attempting to create a list with custom list markers, I encountered an issue. An example from MDN is provided: li::marker { content: '✝ '; font-size: 1.2em; } <p>Group known as Mercury Seven:</p> <ul> <li& ...

Navigation bar text fails to display

Just starting out and trying to create a basic navigation bar, but I can't seem to get the links to show up. All that displays are the logo image and the hamburger icon. How can I make the links visible on the nav bar? Appreciate any help! <!DOCTYP ...

Refresh the CSS without having to reload the entire page

I am working on a web page that operates on a 60-second timer. The code snippet below is responsible for updating the content: protected void RefreshButton_Click(object sender, EventArgs e) { ReportRepeater.DataBind(); ReportUpdatePane ...

Utilizing repl.it for a database in Discord.js

I've created a database script on repl.it and it seems to be functioning properly. However, I keep encountering null values in the users' database. Here's my code snippet: client.on("message", async (message) => { if (messag ...

Reposition the span element to the right of the div tag

I need help adjusting the positioning of the elements in this HTML code. How can I move the span element with the image to the right of the div tag? Here is the code snippet: <div style='width:600px;padding-top: 2px;padding-bottom: 1px'& ...

Getting the Request Body Content in Express Middleware

Currently, I am in the process of developing a small API logger to use as an Express middleware. This logger is designed to gather data from both the request and response objects, then store this information in a JSON file on disk for later reference. Her ...

Contents of the container are not displayed in a single line

What could be causing the first element not to align with the other elements in the container? I'm having trouble figuring out why this is happening. The code snippet seems to work, but when I implement it on the webpage, the alignment issue arises. W ...

What prevents Django websites from being embedded within another HTML (iframe)?

I attempted to include a Django form within another HTML page, but it's not functioning correctly. I've tried on several of my other Django sites with no success. I even tested it on other websites as well. Is there a restriction on using Django ...

Tips for stopping Infinite Scroll from loading pages when the tab is inactive

I'm currently developing a website using Bootstrap 4 and jQuery, which consists of 3 tabs, each containing masonry elements loaded on scroll with the Infinite Scroll plugin. I'm trying to figure out a way for the Infinite Scroll to only load cont ...

Performing a function when the ondrop event of a <li> element is triggered

Is there a way to trigger a code-behind click function on the ondrop event of an <li> element? Additionally, I would like to know if it's possible to force a postback on the onclick event. Any ideas on how to achieve this? Just to clarify, thi ...

How to trigger an update of the useEffect() hook when a button is clicked

I am working with a functional component that contains a button and uses the "useEffect()" hook. My goal is to trigger a re-render of the component, updating the useEffect() hook when the button is clicked. const Emp_list = (props) => { useEffect(() ...

A guide to activating an input field based on the value of another input field in AngularJs

An AngularJs form requires the user to input the number of hours worked. If the value entered is 0, an additional question should be displayed for the reason why no work was done. <label>Hours worked:</label> <input ng-model="hours" type="n ...

Adjust the position and size of an image by hovering over it with your

I'm currently working on implementing a button menu for my website, but I'm facing an issue with the hover effect on images. You can check out what I've done so far at http://jsfiddle.net/tNLUx/ What I want to achieve is when hovering over ...

Preloader will properly handle websocket connections along with pace js

I recently implemented a preloader on my website built with Ruby on Rails. Everything seems to be working perfectly, except for the fact that due to Pusher websockets, the preloader does not stop and keeps running indefinitely. I attempted to address this ...

Is there a way to programmatically fetch files from a MySql / Node.js server?

I've been working on my CRUD app and I'm currently focusing on downloading files from a MySql Nodejs server. Here are the steps I have accomplished so far: I created a function in userContoller.js to query the MySql database for the id=179 (just ...

Error: The function execute_script() is expecting between one and two arguments, however three arguments were provided

While attempting to utilize the Selenium method execute_script() in an automated UI test script, I encountered a type error. The error message indicates that there are too many arguments being passed. TypeError: execute_script() takes from 1 to 2 positiona ...