Transition smoothly with a fade-in effect as you scroll through the images, and proceed to

My Objectives:

  1. Implement a scrolling feature where images transition to the next one based on scroll movement.
  2. Create a cycle of images that automatically progress, with the view transitioning to the bottom section once all images are viewed. Currently facing an issue where scrolling causes the view to move away from the image and onto other parts of the page, making it difficult to focus on the changing images within the viewport.
  3. Add a fadeIn effect or another animation when switching to the next image.
  4. Enable scrolling up functionality to reverse through the image sequence.

If there's a jQuery plugin that accomplishes this, please share your recommendations.

Check out the coding example: http://jsfiddle.net/jzhang172/gcSe8/145/

$(document).ready(function () {
    $(window).scroll(function () {
        if ($(document).scrollTop() > 100) {
            $(".img-container > img").fadeIn("slow").attr('src',' http://vignette3.wikia.nocookie.net/pokemon/images/1/13/007Squirtle_Pokemon_Mystery_Dungeon_Explorers_of_Sky.png/revision/latest?cb=20150105230449');
        } else if ($(document).scrollTop() > 110) {
   $(".img-container > img").fadeIn("slow").attr('src','http://vignette2.wikia.nocookie.net/pokemon/images/5/52/417Pachirisu_Pokemon_Ranger_Shadows_of_Almia.png/revision/latest?cb=20141021151508');
        }
    });
});
.left{
  position:fixed;
  left:0;
  height:100%;
  width:200px;
  background:black;
  color:white;
  font-size:20px;
  text-align:center;
}
body,html{
margin:0px;
}
.bottom{
  height:500px;
  width:100%;
  background:gray;
 
}
.bottom p{
  text-align:center;
  font-size:40px;
}
.img-container{
  height:700px;
  width:100%;
}
.img-container img{
  height:100%;
  width:auto;
}
.img-container p{
  position:absolute;
text-align:center;
color:#00FFF5;
font-size:30px;
margin:300px;
background:black;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="left">

  <p>
  This is fixed!
  </p>

</div>
<div class="img-container">
<p>
This section should stay focused on image until all images have been scrolled through and then it can go to the bottom.
</p>
  <img src="https://i.kinja-img.com/gawker-media/image/upload/unnbgkdbmsszmazgxkmr.jpg">
  
</div>

<div class="bottom">
  <p>
  Please don't cover me
  </p>
</div>

Answer №1

Consider trying this solution:

$(document).ready(function () {
  var images_index = 0;
  var act_cycle = 0;
  var n_cycles = 5;
  var images = ["https://i.kinja-img.com/gawker-media/image/upload/unnbgkdbmsszmazgxkmr.jpg","http://vignette3.wikia.nocookie.net/pokemon/images/1/13/007Squirtle_Pokemon_Mystery_Dungeon_Explorers_of_Sky.png/revision/latest?cb=20150105230449","http://vignette2.wikia.nocookie.net/pokemon/images/5/52/417Pachirisu_Pokemon_Ranger_Shadows_of_Almia.png/revision/latest?cb=20141021151508",]
  $(window).on('DOMMouseScroll mousewheel', function (e) {
    if ($(".img-container").is(':hover')){  
      if (e.originalEvent.wheelDelta < 0) {
      if(images_index < images.length-1){
          $(document).scrollTop(".img-container");
          e.preventDefault();
          e.stopPropagation();
          if(++act_cycle % n_cycles == 0){
            act_cycle = 0;
            $(".img-container > img").hide().attr('src',images[++images_index]).fadeIn("slow");
          } 
        }
      } 
      else {
        if(images_index > 0){
          $(document).scrollTop(".img-container");
          e.preventDefault();
          e.stopPropagation();
          if (--act_cycle == -n_cycles){
            act_cycle = 0;
            $(".img-container > img").hide().attr('src',images[--images_index]).fadeIn("slow");
          }
        }
      }
     }
  });
});
.left{
  position:fixed;
  left:0;
  height:100%;
  width:200px;
  background:black;
  color:white;
  font-size:20px;
  text-align:center;
  z-index: 2;
}
body,html{
margin:0px;
}
.bottom{
  height:500px;
  width:100%;
  background:gray;
 
}
.bottom p{
  text-align:center;
  font-size:40px;
}
.img-container{
  height:700px;
  width:100%;
  z-index: 1;
}
.img-container img{
  height:100%;
  width:auto;
  z-index: 1;
}
.img-container p{
  position:absolute;
text-align:center;
color:#00FFF5;
font-size:30px;
margin:300px;
background:black;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="left">
  <p>
  This is fixed!
  </p>
</div>
<div class="img-container">
  <p>
    This section should stay focused on image until all images have been scrolled through and then it can go to the bottom.
  </p>
  <img src="https://i.kinja-img.com/gawker-media/image/upload/unnbgkdbmsszmazgxkmr.jpg">
</div>
<div class="bottom">
  <p>
    Please don't cover me
  </p>
</div>

Insight:

The process involves transitioning between images based on scrolling movements.

To address this issue, an array containing all the images was utilized, with the src updating according to the index of the array modified by scroll direction determination via wheelDelta.

An iterative cycling through images will occur whereafter the view shifts downward once all images have been viewed. The actual problem arises from the fact that when scrolling, the view does not remain on the current image but moves down the page.

To prevent normal scrolling, DOMMouseScroll and mousewheel events were employed alongside preventDefault and stopPropagation only triggering logic if the img-container is hovered over.

A fade-in effect accompanies the transition to the next image (an alternative animation may be implemented).

The sequence involved first fading out, followed by changing the src, concluding with a fade in operation.

When scrolling upwards, progression regresses along the image sequence.

This regression was effectively resolved using the array of images. Additionally, z-index adjustments were made to accommodate jQuery's fadeIn/Out behavior, combined with scrollTop for maintaining image focus during transitions.

UPDATE: To customize the image change frequency, modify the value assigned to 'n_cycles' variable (set at 5 as per your comments).

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

What is the best way to eliminate the gap between two columns of square containers?

ref image How can I create equal spacing between two columns of blocks? Please help me with the following code: <div class="row"> <div class="col-md-6"> <img src="./img/02.jpg&qu ...

Learn the process of triggering an Ajax request by clicking on a Table row

I am facing an issue with my table. Whenever I click on a row, the <TR> element gets assigned the class "selected". My goal is to capture the content of the first <TD> element in that row (which represents an ID), and then make an Ajax request. ...

Retrieving selections from a group of checkboxes and managing their addition or removal in an array

Currently, I am in the process of creating a form that includes a group of checkboxes. My goal is to be able to capture the value of a specific checkbox when it is clicked and add it to an Array using the useState hook. If the checkbox is unchecked, I wan ...

Guide on dynamically importing a module in Next.js from the current file

I am facing a challenge where I have multiple modules of styled components in a file that I need to import dynamically into another file. I recently discovered the method for importing a module, which requires the following code: const Heading = dynamic( ...

Deactivate certain days in Material UI calendar component within a React application

Currently, my DatePicker component in React js is utilizing material-ui v0.20.0. <Field name='appointmentDate' label="Select Date" component={this.renderDatePicker} /> renderDatePicker = ({ input, label, meta: { touched, error ...

Displaying Kartik's growling animation using AJAX within Yii2 framework

Utilizing kartik growl to display a message via ajax success I attempted the following: This is the javascript code: $.post({ url: "forwardpr", // your controller action dataType: 'json', data: {keylist: keys,user:userdata}, success: f ...

What's the best way to modify HTML element classes using Javascript?

I have designed a custom cms theme with various customization options that I wish to showcase in a live demo. My goal is to implement Javascript style switchers or modifiers where users can choose values from checkboxes or select tags, and see their select ...

combine two JSON objects into a single object based on their unique identifiers

I am facing a challenge with two JSON objects that I have: Object 1: { "jcat":[ { "TITLE":"SEO", "ID":"27", }, { "TITLE":"Functions and Events", "ID":"2" }, ] } Object 2: { "job":[ { ...

Having trouble downloading a PDF file on a local server with React and the anchor tag element

Having trouble downloading a pdf file from my react app to my Desktop. I've reached out for help with the details How to download pdf file with React. Received an answer, but still struggling to implement it. If anyone new could provide insight, that ...

Persisting Big IndexedDB in the Browser

As we embark on the development of a Line of Business (LOB) HTML5 web application, our key objective is to ensure that the application has offline capabilities. Our plan involves retrieving a substantial amount of SQL data from the server and storing it in ...

Adjustable width (100%) and set height for SVG

I am attempting to insert an SVG object onto my HTML page with a width of 100% and a fixed height. Upon viewing my fiddle, you will notice that the height of the dark-grey object changes based on the window proportions, which is not the desired outcome. ...

What is the best way to send a variable to a URL when a link is clicked?

Recently, I started learning PHP and ran into a challenge while working on a school project. The specific issue that I'm facing is how to pass variables to a URL when a link is clicked. Essentially, my problem involves a dropdown menu displaying diffe ...

AJAX: How to handle a successful POST request?

I have been recently exploring AJAX and I can see why I hesitated to delve into this particular area of JavaScript; it appears quite intricate. Most discussions seem centered around how to SEND data via POST, with little focus on what happens once the POS ...

What are some ways to customize the text and button location for Bootstrap 5's file input?

Bootstrap 5's input type file seems too simplistic. Check it out here https://i.stack.imgur.com/VZ0h5.png I am curious about three things: Can the "Choose file" button be moved to the right? Is it possible to change the message that says "No files ...

Preventing Event Loop Blocking in Node.js: The Key to Streamlining Performance

I am currently working on developing two APIs using Express.js. The tasks for both APIs are quite straightforward. The first API involves running a for loop from 1 to 3,000,000, while the second API simply prints a string in the console. All the necessary ...

Encountering a node globby error when implementing multiple patterns

Currently, I am successfully using node glob for folder1 as shown below: glob('folder1/*.js'), function(err, files){ if (err) { console.log('Not able to get files from folder: ', err); } else { files.forEach(function (file) ...

Is there a way for me to either fulfill a promise or face failure?

Currently, I am working on creating a Thennable function that may return a promise based on its parameters. However, there is a possibility that the parameters are invalid which would require breaking the promise chain with something unexpected. What can b ...

Is it possible to create a hyperlink in the <button> element?

Having been immersed in HTML5 for quite a while now, I recently encountered a challenge while working on my login/register page project. I wanted to create a button that would redirect me to another HTML page upon clicking. While I am familiar with the < ...

Unable to properly shut the sliding-over modal

I have implemented a customized version of the codrops slide & push menu (http://tympanus.net/codrops/2013/04/17/slide-and-push-menus/) to create an overlay on my webpage. However, I am facing difficulty in closing it using another link. Any assistance on ...

I'm baffled on how to find access to ParametricGeometry within Three.js

I've been looking into how to access ParametricGeometry because I keep encountering this message when I attempt to use it: "THREE.ParametricGeometry has been relocated to /examples/jsm/geometries/ParametricGeometry.js" Any ideas on how to do this wou ...