How come I am unable to scroll beyond my parallax section unless I move the mouse first?

Currently, I am working on a webpage that includes a Parallax landing image. In order for the Parallax effect to function properly, the image has a greater height, requiring users to scroll down. This leads to the appearance of a second scrollbar specifically for the Parallax effect. Everything seems fine up to this point. However, an issue arises when I reach the end of the Parallax image - the second scrollbar does not automatically activate, forcing me to move the mouse slightly to continue scrolling through the normal content of the webpage.

If you would like to see an example of the problem I'm facing, click on this link: Codepen

I'm wondering if there is a way to enable continuous scrolling after reaching the end of the Parallax image without having to move the mouse first.

* {
          box-sizing: border-box;
        }
        /* CSS code for Parallax effect */
    
      

          <!-- HTML code for creating the Parallax effect -->
        
      

Any suggestions or assistance on resolving this issue would be greatly appreciated!

Answer №1

Let's start with addressing the scrolling issue by adding a position: relative; in the .parallax class. This will help eliminate the double scroll problem.

The scrolling problem you are encountering is browser-specific and not caused by your code (it works fine on Firefox but not on Chrome, for example). Therefore, there is no direct "fix" for it.

However, there are alternative methods to implement parallax without facing this issue, such as manually scrolling each parallax layer without relying on the browser's scroll functionality.

Alternatively, you can simulate a click event when reaching the top or bottom of the scroll to bypass the issue:

$('div').on('scroll', checkScroll);

function checkScroll(e) {
  var element = $(e.currentTarget);

  if (element[0].scrollHeight - element.scrollTop() == element.outerHeight()) {
    $("#parallax").trigger("click");
  } else if (element.scrollTop() == 0) {
    $("#parallax").trigger("click");
  }
}

Answer №2

When you see two scrollbars, it is actually the intended behavior as per the design. Unfortunately, you cannot change this behavior, but you can adjust your solution to align with the intended behavior, like displaying only one scrollbar instead of two.

The parallax effect in your design is created using the perspective and translateZ properties. In order for this effect to work properly, the container of the parallaxed items must have the perspective property, and the items themselves must be direct descendants of the container. In the solution provided below, I have set the perspective attribute to the body element, making sure that the parallax effect only occurs when scrolling the body element. By setting the overflow of the html element to hidden, the scrollbar will then appear on the body element.

My approach is similar to the one shared by Dennis Ranish, with a slight difference. I have utilized the background-image and

background-position: center bottom
properties to automatically center the image regardless of its width, eliminating the need to know the intrinsic size of the image. This method offers more flexibility compared to using fixed units like margin-left: -1500px. Additionally, I have used div elements instead of img elements to address possible issues with Vue, enhancing the overall functionality of your design.

Moreover, I have adjusted the content position using top: 100% and position: relative properties to ensure that the content appears directly below the image. You can find the solution below:

* {
  box-sizing: border-box;
  margin: 0;
}

html {
  overflow: hidden;
}

body {
  overflow-x: hidden;
  background-color: #fedcc8;
  height: 100vh;
  -webkit-perspective: 100px;
  perspective: 100px;
}

div[class^="parallax__layer"] {
  position: absolute;
  bottom: 0;
  left: 0;
  width:100vw;
  height:100vh;
  background-repeat: no-repeat;
  background-position-y: bottom;
  background-position-x: center;
}

h1 {
  font-family: Helvetica;
  color: #fff;
  text-align: center;
}

.parallax__content {
  background: #2d112b;
  top: 100%;
  position: relative;
  padding: 200px 100px;
}

.parallax__layer--zero {
  background: url('https://github.com/samdbeckham/blog/blob/master/dev/_assets/images/articles/firewatch/layer_0.png?raw=true');
  -webkit-transform: translateZ(-300px) scale(4);
  transform: translateZ(-300px) scale(4);
}

.parallax__layer--one {
  background: url('https://github.com/samdbeckham/blog/blob/master/dev/_assets/images/articles/firewatch/layer_1.png?raw=true');
  -webkit-transform: translateZ(-250px) scale(3.5);
  transform: translateZ(-250px) scale(3.5);
}

.parallax__layer--two {
  background: url('https://github.com/samdbeckham/blog/blob/master/dev/_assets/images/articles/firewatch/layer_2.png?raw=true');
  -webkit-transform: translateZ(-200px) scale(3);
  transform: translateZ(-200px) scale(3);
}

.parallax__layer--three {
  background: url('https://github.com/samdbeckham/blog/blob/master/dev/_assets/images/articles/firewatch/layer_3.png?raw=true');
  -webkit-transform: translateZ(-150px) scale(2.5);
  transform: translateZ(-150px) scale(2.5);
}

.parallax__layer--four {
  background: url('https://github.com/samdbeckham/blog/blob/master/dev/_assets/images/articles/firewatch/layer_4.png?raw=true');
  -webkit-transform: translateZ(-100px) scale(2);
  transform: translateZ(-100px) scale(2);
}

.parallax__layer--five {
  background: url('https://github.com/samdbeckham/blog/blob/master/dev/_assets/images/articles/firewatch/layer_5.png?raw=true');
  -webkit-transform: translateZ(-50px) scale(1.5);
  transform: translateZ(-50px) scale(1.5);
}

.parallax__layer--six {
  background-image: url('https://github.com/samdbeckham/blog/blob/master/dev/_assets/images/articles/firewatch/layer_6.png?raw=true');
  -webkit-transform: translateZ(0px) scale(1);
  transform: translateZ(0px) scale(1);
}
<div class='parallax__layer--zero'></div>
<div class='parallax__layer--one'></div>
<div class='parallax__layer--two'></div>
<div class='parallax__layer--three'></div>
<div class='parallax__layer--four'></div>
<div class='parallax__layer--five'></div>
<div class='parallax__layer--six'></div>
<div class='parallax__content'>
  <h1>Hello y'all, this parallax works!</h1>
</div>

Answer №3

Don't worry, what you're encountering is not an issue. Your scenario involves two elements with scroll bars, one within the other. This is similar to the code snippets on this page where scrolling behavior is intentional. In the case of parallax effects, only one scrollable element is needed without the need for extra divs. Here's a simplified approach...

html {
  overflow: hidden;
}

body {
  margin: 0;
  background-color: #fedcc8;
  height: 100vh;
  overflow-x: hidden;
  -webkit-perspective: 100px;
  perspective: 100px;
}

... (CSS code continues) ...

/* Additional images and content structure here */

To achieve the parallax effect, adjust the body's perspective and set the html overflow to hidden. Ensure proper alignment and scaling of elements for the parallax effect. By positioning images within divs sized to the screen with bottom alignment and negative z-index, you can create the desired effect. Remember to contain all elements in one scrollable element for smooth scrolling. Feel free to customize the positioning of the mountains based on your design requirements.


Key takeaway: Keep scrolling within one element for a seamless experience. We hope this explanation clarifies the concept for you.

Answer №4

This piece of code features a smooth scrolling effect. To enhance your code, I recommend checking out this resource. I hope you find it helpful.

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body,
html {
  overflow: hidden;
  background-color: #fedcc8;
}

body {
  height: 500px;
  height: 100vh;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-perspective: 100px;
  perspective: 100px;
  -webkit-perspective-origin-x: 100%;
  perspective-origin-x: 100%;
}

section {
  position: relative;
}

.cover {
  color: #fff;
  background: #2d112b;
  padding: 1rem;
}

.cover2 {
  padding: 1rem;
  background: #fedcc8;
}

.parallax__group {
  height: 500px;
  height: 100vh;
  -webkit-transform-style: preserve-3d;
  transform-style: preserve-3d;
  -webkit-transition: -webkit-transform 0.5s;
  transition: transform 0.5s;
}

.parallax__layer {
  position: absolute;
  top: 0%;
  left: 0;
  right: 0;
  bottom: 0;
  -webkit-transform-origin-x: 100%;
  transform-origin-x: 100%;
}

...

<section class="parallax__group">
  <div class="parallax__layer parallax__layer__0">
    <img src="https://github.com/samdbeckham/blog/blob/master/dev/_assets/images/articles/firewatch/layer_0.png?raw=true" />
  </div>
  <div class="parallax__layer parallax__layer__1">
    <img src="https://github.com/samdbeckham/blog/blob/master/dev/_assets/images/articles/firewatch/layer_1.png?raw=true" />
  </div>

...

</section>

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

Having trouble with jQuery loading for the first time

I am having trouble getting the jQuery to load properly. My goal is to toggle classes on specific items identified by their ID. When an item is clicked, I want it to have the class "menu-selected" while the other item has the class "unselected." I have i ...

Updating user credits through the Model::factory() method is a common practice in my workflow

I need to update the UserCredits after a purchase. For example, if a user currently has 10 credits and purchases 10 more, I want to add the purchased credits to their existing total. The goal is to increment the current credit score with the new credits ...

Adjust the size of the event bar on the FullCalendar resourceTimeline view

In my implementation of FullCalendar v6, I am displaying 6 months worth of data in the calendar, with each slot representing a one-month period. The issue I am facing is that when creating an event spanning 10 days, it currently takes up the entire width o ...

Trigger offcanvas modal and backdrop simultaneously using Bootstrap v5.0

Working with Bootstrap v5.0 offcanvas has been smooth sailing until I hit a roadblock. Clicking on the offcanvas button seems to be triggering both the offcanvas-backdrop and modal-backdrop divs simultaneously. <div class="modal-backdrop fade show ...

What techniques are most effective for concealing a div container through css?

I attempted to hide the #div element using CSS: #div{ display: hide; } However, the method did not work as expected. ...

Tips for implementing owl carousel in Nuxt.REACT_UNITS_CODIFY

Is there a way to make the script function on every page without the need for these pages to be reloaded? I have the Owl Carousel script in my static folder, and I have already included it in nuxt.config.js as shown below: head: { title: 'title&ap ...

typescript - transforming text into numerical values

newbalance = (Number(this.balance)) + (Number(this.pastAmount)); The result for my newbalance calculation is coming back as undefined, even though this.balance is 34 and this.pastAmount is 23. I've set this up in the controller and I'm trying t ...

Want to develop a web application and incorporate Ajax into it?

I'm sure many of you have created an online application that streamlines processes and saves time and money for your company. So, how did it go when you added some Ajax to enhance the user experience after developing the application? Any recommendat ...

Make window.print() trigger the download of a PDF file

Recently, I added a new feature to my website allowing users to download the site's content by following these instructions: Printing with Javascript || Mozilla Dev. Essentially, the user can print a newly formatted site stored in a hidden iframe. Now ...

Angular JS may encounter a cross domain problem when attempting to post on a third-party website

HTML Code: <div ng-app="myApp" ng-controller="myController"> <div> <input type="button" data-ng-click="submit()" ...

Steps for implementing a single proxy in JavaScript AJAX with SOAP, mirroring the functionality of the WCF Test Client

I am working with a WCF web Service and a javascript client that connects to this service via AJAX using SOAP 1.2. My goal is to pass a parameter to instruct the AJAX SOAP call to use only one proxy, similar to how it is done in the WCF Test Client by unch ...

Error encountered in Vue 3 typescript: Uncaught TypeError - this.$on function is not defined in this context

Just set up a fresh installation of Vue 3 using vue-cli and typescript. Everything seems to be running smoothly, but as soon as I incorporate the https://vue-select.org/ package, I encounter this error in the browser console: Uncaught (in promise) TypeErro ...

Debugging the Force-Directed D3 Graph

I stumbled upon a fantastic article that provided a detailed guide on creating a beautiful D3 force layout graph. However, I'm facing some difficulties with the JSON source: The "links" attribute in the author's JSON doesn't seem clear to m ...

Disappearance of external page upon refreshing - jquery mobile

I'm in the process of developing a jQuery mobile application that loads external pages into a specified div when a link is clicked. These externally loaded pages contain links to additional pages. However, I've noticed that when I click on these ...

Tips for successfully implementing overflow-x in a timeline layout without causing any format disruptions

I've been working on a dynamic timeline design that adapts to different screen sizes. I applied overflow-x property to prevent horizontal scrolling in the mobile version, making the burger menu's sub-items visible without requiring a click. Howev ...

Arranging elements using the ng-repeat directive in AngularJS

My question pertains to an array I am working with: $scope.answers=["","","",""] This array contains several empty elements. <li ng-repeat="item in answers "><input type="text" ng-model="item"/></li> When running this code, an error i ...

Ways to navigate through a webpage without encountering any overflow issues

My window is too small to scroll, but I still need the ability to do so. Is it possible to scroll even when the height of the container is not large enough to display the scrollbar? Below is the code I am using to achieve scrolling: setTimeout(function() ...

How come the state update result is triggering two different responses?

I recently developed a basic TicTacToe game using react-hooks. At times, I notice that the result is displayed before the state update on the screen. https://i.sstatic.net/LMDeZ.png Other times, the result shows up after the update is visible on the scr ...

There seems to be an issue with the performance of Google script .setFormula when used in conjunction with the

Hello everyone, I have written a script that inserts formulas in a specific range and set up a trigger for it to run between 01:00 and 02:00 AM. The purpose is to subscribe the values with the formulas and then paste the resulting values. However, I am fac ...

What is the best way to choose elements that are not followed by a specific element?

My HTML structure consists of repeating pairs of img and p tags. Often, the img tag is missing from the sequence. <img> <p></p> <img> <p></p> <img> <p></p> <p></p> <p></p> <i ...