The two divs cascading in a V shape as you scroll

Being new to CSS and jQuery, I am currently delving into various animations. My current focus is on creating an animation similar to the one on domain.me.

For this project, I am utilizing jQuery's scrolltop() to track scroll position and using console.log to display the values in the console. I manually implemented if statements and addClass() based on the scroll position. Below is the complete code (both style and script are in the same file).

js fiddle

$(window).scroll(example);

function example() {
  var tempScrollTop = $(window).scrollTop();
  console.log("Scroll from Top: " + tempScrollTop.toString());

  if (tempScrollTop > 20 && tempScrollTop < 50) {
    $("#div1").addClass("slide");
    $("#div2").addClass("slider");
  }
  
  if (tempScrollTop > 50 && tempScrollTop < 100) {
    $("#div1").addClass("slide1");
    $("#div2").addClass("slider1");
  }
  
  if (tempScrollTop > 100 && tempScrollTop < 200) {
    $("#div1").addClass("slide2");
    $("#div2").addClass("slider2");
  }
  
  if (tempScrollTop > 200 && tempScrollTop < 300) {
    $("#div1").addClass("slide2");
  }
};
#mainbord {
  border: 5px solid black;
  height: 100%;
  width: 100%;
  background-image: url("2.jpg");
}

.divv {
  border: 1px solid black;
  width: 200px;
  height: 200px;
  margin-top: 300px;
  margin-left: 500px;
  border-radius: 50%;
}

.div2 {
  border: 1px solid black;
  width: 400px;
  height: 50px;
  margin-left: 400px;
}

.div3 {
  border: 1px solid black;
  width: 500px;
  height: 500px;
  margin-top: 200px;
}

.div4 {
  border: 1px solid black;
  width: 500px;
  height: 500px;
  margin-top: 200px;
}

.slide {
  background-color: green;
  border: 1px solid black;
  width: 180px;
  height: 180px;
  margin-top: 250px;
  margin-left: 420px;
  -moz-transform: scale(0.2);
  transition: all 600ms ease-in;
  */
}

.slide1 {
  background-color: red;
  border: 1px solid black;
  width: px;
  height: 160px;
  margin-top: 160px;
  margin-left: 400px;
  transition: all 600ms ease-in;
}

.slide2 {
  background-color: blue;
  border: 1px solid black;
  width: 100px;
  height: 100px;
  margin-top: 200px;
  margin-left: 350px;
  -moz-transform: scale(0.2);
  transition: all 600ms ease-in;
}

.slider {
  margin-left: 550px;
  margin-top: background-color:green;
  transition: all 600ms ease-in;
  width: 300px;
}

.slider1 {
  margin-left: 700px;
  background-color: red;
  transition: all 600ms ease-in;
  width: 250px;
}

.slider2 {
  margin-left: 730px;
  background-color: blue;
  transition: all 600ms ease-in;
  width: 250px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>

<div id="mainbord">
  <div id="div1" class="divv">
    <img src="1.png" width=100%,height=100%/>
  </div>
  <div id="div2" class="div2"></div>
</div>
<div class="div3"></div>
<div class="div4"></div>

Answer №1

To make changes, you need to either delete or switch off the CSS class. As shown in your scenario, the elements contain all classes (slide, slide1, slide2) at the conclusion.

Answer №2

If you have experience with the chrome dev console, take a look at this https://i.sstatic.net/rakuK.png

Do you see the .me icon <div id ="slikadiv"..? (refer to the screenshot) Try slowly scrolling in the web section and observe how the CSS properties like width, top, and left change.

Create your own function within the .scroll jquery function to control the movement of the icon.

Don't forget to explore the other CSS properties as well.

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

How do I make sure an onchange event triggers when updating element values in jQuery?

In my view, I have an address block that can update some data when a user clicks a checkbox. This functionality is achieved through the following javascript function: <script type="text/javascript"> $().ready(function() { $("#UseAccountA ...

Deciding whether to use Device WebView Kit or HTML for your project is

I am a bit confused about creating a website for mobile devices. If I have a specific webpage in mind that I want to target towards mobile devices, do I need to use the native webview kits provided by iOS, or can I simply code in HTML, PHP, Javascript, an ...

Pattern matching for replacing <a> tags

As a beginner in the world of regular expressions, I am eager to learn more about it. Currently, my goal is to extract only the inner text from an HTML tag and remove the surrounding tags. For example: Original: Lorem ipsum <a href="http://www.google.e ...

Is there a method in AngularJS to have $http.post send request parameters rather than JSON?

I have come across some older code that utilizes an AJAX POST request using jQuery's post method. The code looks something like this: $.post("/foo/bar", requestData, function(responseData) { //do stuff with response } The request ...

When using Laravel's Response::json, a cross-domain error may still occur in the browser despite setting the header to Access-Control-Allow-Origin

I am facing a perplexing Laravel 4 issue. I have set up two methods in the same controller, which is declared to be restful. The problem arises when the ajax request comes from a different domain. The first method does not work: public function getOwnlis ...

Can you provide guidance on achieving responsiveness using Bootstrap, CSS, and HTML?

I am currently developing a portfolio website and I have encountered a bug in my code. I need assistance with placing the footer below the pricing card. Thank you. https://i.sstatic.net/qYMvd.jpg HTML : FOOTER SECTION : <footer class="footerP"> ...

Running system commands using javascript/jquery

I have been running NodeJS files in the terminal using node filename.js, but now I am wondering if it is possible to execute this command directly from a JavaScript/jQuery script within an HTML page. If so, how can I achieve this? ...

Conceal element with transparent overlay without affecting the background

Looking to add animation to a snippet where the login menu rolls out? Consider two methods: adjusting the left position of the login menu or using another div on top to slowly reveal the login menu after moving it. The challenge lies in maintaining trans ...

increasing the size of the input field on the lower row of the form

I have a form with two rows of text boxes. The first row contains three text boxes, while the second row should only have one text box that spans 100% of the width. Here is the current code: <div class="row"> <div class="col-md-4"> ...

Using "margin: 0 auto" does not function properly if a specific width is specified

While developing a search tool for my website, I encountered an issue with centering elements. I created a main div container with margin: 0 auto, which successfully centered the container. However, when I tried to center another element inside it using ma ...

When using jQuery and AJAX together, it seems that the POST method is returning

Currently experimenting with Cloud9. The current project involves creating an image gallery. On the initial page: There are a few pictures representing various "categories". Clicking on one of these will take you to the next page showcasing albums fro ...

Please dismiss the pop-up and reload the main page

home.php <a href='javascript:void(0);' onclick="pepz('<?php echo"ppc-mngt_transfer.php?id=$i->sm_id"; ?>', 'myPop1',400,400)"><?php print"$i->sm_jo<br>$i->sm_custo_name"; ?></a> ppc-mn ...

Automatically conceal a div or flash message after a short period of time by utilizing CSS3 in a React

I am relatively new to the React environment and recently created a basic component for a bookmarking feature. Essentially, when the favourite icon is clicked, an ajax call is sent > a record is created in the database > on ajax success, a flash me ...

Utilizing jQuery Extensions with Greasemonkey (e.g. tooltips)

I have been experimenting with the tipsy jQuery plugin in my greasemonkey script, and for the most part, it's going well. I am utilizing the @require meta tag to bring in the jquery and tipsy js files, but there are a few challenges that I need to add ...

Modify enum values in button click within CodeIgniter

Is it possible to dynamically update enum data type values with a button click in Codeigniter? <?php foreach($req as $row): ?> <div class="col1"> <?=$row->Offer?> </div> <div class=""col2> <button ...

Creating a dynamic layout in a fresh window with jQuery: A step-by-step guide

My goal is to create a dynamic layout using jQuery. The concept involves allowing the user to choose a width and height, which will determine the number of images displayed in rows and columns. The desired outcome is for the user to select a grid size (e. ...

After filling out the form, the user's entered information is instantly shown on the same page

I want to create a form where my friend can input information that will be displayed on the same page. For example, when he enters the title in a text field and clicks submit, it should appear in the title box. Additionally, he should be able to enter va ...

Crafting a dynamic CSS 'trail' effect when hovering

I am attempting to create a visually appealing CSS menu using primarily CSS, with just a touch of jQuery as well: Here is the concept: +------------------------+ | | | | | +---+ | | | ...

Adjust the color of the font awesome exclamation triangle symbol

Is it possible to use font awesome's exclamation triangle icon with the exclamation mark in red and the triangle's background in white? I've tried changing the color to red but it didn't work as expected. Can anyone provide guidance on ...

Following the same occurrence using varying mouse clicks

I am currently exploring the most effective method for tracking file downloads (specifically, pdf files) on my website using Google Analytics (UA). I understand that by utilizing <a href="book.pdf" onClick="ga('send','event','P ...