Move the image independently of the mouse-pointer to see the entire scroll overflow

Currently, there is a full-page scrollable background image with a div positioned at the bottom of the page. However, I am facing an issue where I can only scroll the image when the mouse-pointer is hovering over it and not over the bottom div. Is there a solution to make the image scrollable from any point on the page?

To better illustrate my current setup and the desired functionality, you can refer to this JSfiddle.

Answer №1

Given that #bottom is located outside of the scrolling area, a bit of JavaScript will be necessary.

  • Create an event listener for scrolling on #bottom
  • Prevent the scroll from being intercepted by #bottom's parent element (in this case, the document)
  • Implement similar functionality to your scrolling area (#image in this instance)

To accomplish this, consider using the following code snippet:

const image = document.getElementById('image')
const bottom = document.getElementById('bottom')

function handleBottomScroll(event) {
  event.preventDefault();
  image.scrollTop = image.scrollTop - event.wheelDeltaY
}

bottom.addEventListener('wheel', handleBottomScroll)

Explore the JSFiddle example here: https://jsfiddle.net/uniqueusername/gdwzp1t4/7/

Answer №2

To prevent scrolling, you can use the CSS property pointer-events: none; on the element with the class .bottom. Here is an example of how it could be implemented:

body {
  margin: 0;
}

.main {
  --bottom-height: 100px;
  width: 450px;
  height: 100vh;
  position: relative;
}

.bottom {
  background-color: red;
  position: absolute;
  height: var(--bottom-height);
  inset: auto 0 0;
  pointer-events: none;
}

.image {
  overflow: auto;
  position: absolute;
  inset: 0;
  padding-bottom: var(--bottom-height);
}

.image img {
  width: 100%;
  height: calc(100% + var(--bottom-height));
  object-fit: cover;
  display: block;
}
<div class="main">
  <div class="image">
    <img src="https://images.unsplash.com/photo-1684010850063-add4e5fec6a7?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxlZGl0b3JpYWwtZmVlZHwxOHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=900&q=60" />
  </div>
  <div class="bottom">
    This section will not scroll when the mouse hovers over it. How can this behavior be changed?
  </div>
</div>

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

Subheaders that stay in place while scrolling through a table with a stationary header

My goal is to design a table with a fixed header that allows the body to scroll under the header. While this is a common design, I am facing the challenge of implementing sticky subheaders. These subheaders should scroll along with the table until they rea ...

What strategies can be implemented to improve the load time for bigvideo.js?

Why are my load times extremely slow for such a small site? I had hoped to display an image before the video loads, but they both seem to load simultaneously, even if the video takes forever to load. This is my HTML: <div id="bigvid"> <div cla ...

Exploring the variations between getRequestHandler and render functions in Custom Next.js applicationsIn a

Greetings, I found it quite unexpected that there is a lack of information available on the functionalities of the getRequestHandler and render functions within the next package. As I am in the process of setting up a custom server, I am curious about wh ...

I'm struggling to figure out where I went wrong with the Mongoose unique pre-save validation. What could

I am in the process of developing a User model that requires a unique username. Below is the code snippet for the model: var mongoose = require("mongoose"); var Schema = mongoose.Schema; var UserSchema = new Schema({ username: String, password: ...

Guide on adding a local text file to a textarea embedded within a webpage

As an aspiring programmer, I am seeking assistance in understanding how to upload a local text file to a textarea within a website that I am currently developing. My expertise lies in HTML/CSS, with a good grasp of Javascript/JQuery, and I am in the proces ...

Below and above the number 10

Struggling with a challenging coding problem, I am completely stumped on how to make it work. function(obj) { if ( (obj < 10) && (obj > 10) ) { return true; } } I've attempted various solutions such as manipulating the varia ...

Showcase a variety of random images in the navigation bar using Javascript and HTML

In order to create a unique experience for mobile users, I have implemented multiple images for my navigation bar menu icon toggle button. These images are stored in an array and a random image is selected each time the page loads using Math.Random. Howeve ...

Ensure the content of the file is valid prior to uploading

Is there a method to verify the correctness of a yaml file's syntax and data before uploading it to a server? ...

Learn how to hide elements on print pages conditionally in Vue.js using CSS or JavaScript

I am currently using the Vue framework to work on printing webpages for my application. I have an issue that needs a solution, which I will explain below. <template> <div id = "intro" style = "text-align:center;"> <div ...

Update the text within a table in real time by simply checking a box

I've got some data in JSON format that I've converted into an HTML table. Now, my goal is to update the text from False to True if a checkbox is checked. How can I achieve this? Below is the code used to create the HTML table: $.each(result, fu ...

The query designed to conduct a thorough search using regex is experiencing some issues and not performing as expected

How can I perform an in-depth regex search in MongoDB using a JavaScript function within the query? Here's an example: db.collection.find( {$where: function() { function deepIterate(obj, value) { var new_value = new RegExp("^"+ ...

What is the best way to retrieve a specific property or attribute of a specific div element after obtaining it from e.target.parentNode?

e.target.parentNode will return this element. <div class="quantity"> <span class="glyphicon glyphicon-minus-sign"></span> <span class="product_Count"> 4 </span> <spa ...

What steps can I take to guarantee that both images and text adapt well to different screen sizes?

Is there a way I can organize my website to display 3 movies per row with the text centered relative to the image? Here is how it currently looks (the red box is just for reference, please ignore): https://i.stack.imgur.com/w2pgN.jpg Also, when I resize m ...

Sorry, but we couldn't locate the page you were looking for. The robots.txt file seems

Hey there everyone, I'm currently working with Nuxt3 and encountering an error when trying to access the robot.txt file. Here's the Robot.txt module that I've integrated. Within my nuxt.config.ts file: export default defineNuxtConfig({ ...

Is it possible to align the scrollbars of two separate divs using JavaScript/jQuery?

In my index.html page, I have two divs where I load different content into each one by selecting the div and injecting the content using jQuery. As a result, each div ends up with a horizontal scrollbar to display its content. My goal is to synchronize the ...

How can I ensure that PrimeNG is functioning properly?

I'm encountering some difficulties setting up PrimeNG correctly to utilize its rich text editor. Despite installing all the necessary components, it's still not functioning as expected. https://i.stack.imgur.com/4kdGf.png This is my package.jso ...

What is the best way to simulate a worker for testing in Jest?

Currently facing a test challenge: import { convertHeicToPng } from './heicUtils'; class Employee { url: string; onmessage: (m?: any) => void; constructor(stringUrl: string) { this.url = stringUrl; this.onmessage = () => {}; ...

What could be causing the video autoplay feature to not function properly when used in conjunction with a bootstrap carousel

My video is not auto-playing. The same code works when placed in a different file, but it's not working on my page. Can anyone help with this issue? The URL where the video is not autoplaying: I have tried everything I can think of to get it working ...

Utilize AngularJS ng-repeat directive to refine JSON objects

I'm working on an angular js controller with a json array that organizes countries by continents. Each continent consists of its own array of countries. //CONTROLLER app.controller('CountryController', function(){ this.continents = ...

Is it possible for a camera to embody the essence of a texture?

I am currently working on a game using HTML/Javascript with Three.js. One of the key features I have implemented is moving the road and allowing the camera to move as if it were attached to a car controlled by arrow keys. Now, my next challenge is to give ...