"Navigate through the page by scrolling with your mouse all the way to 100

Is it possible to trigger an action when a user starts scrolling using the mousewheel? I've searched online but all I found was information on 100% scroll on click. I want the window to automatically be scrolled down to 100% as soon as the user starts scrolling with their mousewheel. Can this be done? Thank you!

Answer №1

To begin with: The issue that arises when trying to forcefully scroll the screen all the way down is that it restricts any further movement on the screen - since each scroll action resets the position.

One approach to address this is by utilizing JQuery and monitoring the scroll event.

Here's an example:

$(document).on('scroll', function(){
    console.log('yeah');
    // window.scrollTo(0,document.body.scrollHeight); // left this commented out
});

You can achieve the same without JQuery as well, just using plain JavaScript

document.onscroll = function(){ 
                      console.log('oh yeah');
                      // window.scrollTo(0,document.body.scrollHeight); // left this commented out
                    }

Answer №3

A simple solution would be to use the following code:

$(window).on("wheel", function (e) {
   if (e.deltaY > 0) // Make sure to determine whether to compare greater than or less than based on your needs
      $("html, body").scrollTop(10000000000);
});

Answer №4

If you're looking for a way to detect any scroll on the page, rather than just mousewheel scrolling specifically, this code might be what you need. It uses jQuery so make sure that's suitable for your project.

$( document ).ready(function() {
    $(window).scroll(function (event) {//Checks if scroll happens
        //set the left offset to 0, set the second one to the height of the document
         window.scroll(0,document.body.scrollHeight);
    });
});

Keep in mind, this script will be triggered by any scroll movement.

Answer №5

1) Insert an unseen hyperlink:

<a id="invisible-scroll-link" href="#end" style="color:black">...</a>

2) When the mouse wheel is scrolled:

$(window).bind("wheel", function (e) {
   if (e.deltaY > 0) {
     $('#invisible-scroll-link').trigger('click');
   }
});

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

Error in React-Native: Unable to locate main project file during the build process

Just integrated cocoapods into a React Native project. After a successful build, RN is throwing this error... https://i.stack.imgur.com/czn2W.png No errors in Xcode during the build process, but Xcode is displaying these warnings https://i.stack.imgur.c ...

Tips on incorporating a dynamic variable value as a class name within a span tag

I am a beginner in the world of JavaScript. Below is the code snippet I am working with: result.push(`<span class="mark">${str.substring(h.startOffset, h.endOffset)}</span>`); Currently, I have a variable called var className = "dynamicvalue" ...

Height adjustment for flexbox children

Can someone assist me with marking up a todo list? I am attempting to set the height of div.main-tasks equal to div.tasks so that the former fills the entire latter. Unfortunately, I am unsure how to achieve this. You can refer to the following image for c ...

Is it possible to adjust the width of Material-UI TextField to match the width of the input text?

Is there a way for Material-UI to adjust the width of the TextField element automatically based on the input text? When creating a form view/edit page and rendering data into fields, I also have parameters set by the server. It would be convenient to have ...

What are the steps for removing rows of data with sequelize?

In my books.js Pug file, I have the following router where I am utilizing Sequelize ORM to find and delete a specific row of data based on the ID. /* - Removes a book. Be cautious, this action is permanent. Consider creating a "test" book for trial d ...

What are the available choices for constructing HTML based on an ajax response?

Are there any alternatives or libraries available for constructing html from an ajax response? Currently, I am taking the json data received, creating the html as a string, and using a jQuery function to insert it into the DOM. However, I believe there mu ...

AngularJS attempting to conceal the popup menu upon clicking outside of the designated area

My HTML structure looks like this: <div> <a href="" ng-click="$scope.show_menu = !$scope.show_menu">Options</a> <div class="options_box" ng-show="$scope.show_menu"> <button>Option1</button> ... ...

What is the method for establishing session or cookie in an HTTPS request to a specific URL?

When making an HTTPS GET request in Node.js to a specific URL, it is necessary to include the session cookie. In this case, I already have the value of the cookie that needs to be sent. var URL = require('url-parse'); var appurl = "https://test ...

Utilizing dynamic data within the ng-template

As a newcomer to Angular, I am facing a challenge in passing a string into a template. My goal is to create a reusable template or component that can display instructions on how to proceed with an action. Currently, I am achieving this by using the follow ...

Sharing jquery variables between an iframe and its parent window

How can I manipulate data between jQuery and iframes? Specifically, how do I retrieve and pass variables from an iframe to the body, and vice versa? Consider the example below. How can I trigger a button click event within an iframe that affects the conten ...

The differences between using the opacity attribute in HTML and the opacity property

There are two distinct methods for adjusting opacity in HTML: <div opacity="0.5"></div> and <div style="opacity: 0.5;"></div> I am familiar with setting these values in JavaScript as well: div.setAttribute("opacity", 0.5); and ...

Troubleshooting Problem with Helvetica Neue Font on Firefox

Recently, I decided to add the Helvetica Neue font to my system. However, upon doing so, I encountered a problem with Firefox browser where the font appeared double when using Helvetica Neue. Is there any available solution for this issue? Here is a scre ...

Positioning div at the top of the body section

Presently, I have this specific designhttps://i.sstatic.net/U4IT4.png The issue I am facing is with the alignment of the jumbotron (boostrap v5). It is currently centered, but I would like it to be positioned at the very top of the body. I have experiment ...

Exploring Javascript/JQuery parameters based on data types

I'm a bit confused about whether the title accurately reflects my question. I need help understanding how jQuery deals with functions that are called with different argument combinations, such as ("Some String", true, function(){}) and ("Some String", ...

Leveraging bootstrap for achieving vertical and horizontal centering of images

My webpage uses bootstrap to display content, and while I've managed to center my images vertically, I'm facing an issue with horizontal centering. I want to ensure that any image, regardless of size, remains within the column/row and adjusts it ...

The power of Angular controllers lies in their ability to facilitate two-way

Currently, I have a controller that acts as a wrapper for ui-router and manages its flow, similar to a menu bar. When a user clicks on a menu item, a function is triggered that changes the ui-router state and broadcasts an event to the inner controllers. E ...

What are some methods for identifying a single attribute element that is duplicated elsewhere on a webpage?

<html> <tr id="userman-orgchart-tree-node-9" class="fancytree-expanded fancytree-folder fancytree-has-children fancytree-exp-e fancytree-ico-ef"> <td> <span class="fancytree-node" style="padding-left: 16px;"> <span class="fancytr ...

Tips on aligning text to the left on mobile devices using CSS and HTML

When viewed on a standard 16:9 computer screen, everything looks perfect with text on the left and an image on the right. However, when it comes to smaller screens like phones, the picture appears on top of the paragraph instead. I am new to this, so any a ...

Tips for ensuring all buttons are evenly spaced from a surrounding div

Here’s the current setup - .box{ background-color: #e61a39; width: 25%; float:left; margin: 0px; text-align: center; min-height: 380px; } #container{ width: 90%; margin: auto; } <section id="container"> <div class="box"> <img src="http ...

The font rendering in Safari appears to have distinct differences compared to other web browsers

My concern is related to the HTML tag below: <a href="/partner-team/team" class="button button__style--1">MEHR</a> This is how the CSS appears: a { text-decoration: none; } .button { padding: 0.2rem 4rem; curso ...