What triggers the scrolling event for a sleek scrollbar?

I've successfully integrated Smooth scrollbar on my website and it's working great. However, I'm now looking to enhance the scrolling experience with some transition effects in the content as it scrolls. My initial idea was to trigger these effects on a scroll event, but since I'm not sure how Smooth scrollbar operates and which object executes on such an event, I attempted the following code without success:

$("#my-scrollbar").on("scroll", function () {
 console.log("scroll"); //not working
});

What triggers the scroll event in this case? Is there an alternative method to incorporate additional effects without solely relying on the scroll event?

UPDATE: Let me provide more context by sharing my code (which utilizes React.js).

index.html

<!DOCTYPE html>
<html>
    <head>
        <title>Implementing Smooth Scrollbar with Parallax Effects</title>
    </head>
    <body>
        <noscript>Please enable JavaScript to view this site.</noscript>
        <div id="my-scrollbar">
            <div id="root"></div>
        </div>
    </body>
</html>

index.js

import React from "react";
import ReactDOM from "react-dom";
import "./website/App.css";
import App from "./website/App";
import Scrollbar from "smooth-scrollbar";

Scrollbar.init(document.querySelector("#my-scrollbar"));

ReactDOM.render(<App/>, document.getElementById("root"));

App.js

import React, { Fragment, Component } from "react";
import $ from "jquery";


class App extends Component {
    componentDidMount() {
       $(document).on("scroll", function (e) {
            console.log(e);
        });

        const h1posX = 64;
        const h1posY = 64;
        $("#section2 h1").css({ transform: `translate(${h1posX}px,${h1posY}px)` });
        window.addEventListener("scroll", function () {
            const distance = window.scrollY;
            console.log(distance);
            if (distance <= $("#section1").outerHeight() / 2) document.querySelector(".container2").style.transform = `translateY(${distance * 1.15}px)`;
            $("#box2").css({ transfrom: `translateY(${distance}px)` });
            $("#section2 h1").css({ transform: `translate(${distance * 0.15}px,${h1posY}px)` });
        }); 
    }

    render() {
        return (
            <Fragment>
                <main>
                    <header>
                        <div className="container2">
                            <h3>Hello world!</h3>
                            <p>Scroll to see smooth scrolling</p>
                        </div>
                    </header>

                    <div id="section1">
                        <h3>Lorem ipsum</h3>
                    </div>

                    <div id="section2">
                        <h1>Dolor sit amet</h1>
                    </div>
                </main>
            </Fragment>
        );
    }
}

export default App;

App.css

header {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    position: relative;
    height: 100vh;
    color: #eee;
    z-index: -1;
    text-align: center;
    background: linear-gradient(135deg, #0056a7, #165fa3, #477aaa);
    animation: fadeIn 1.5s ease-in-out;
}

#section1 {
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1;
    height: 100vh;
    font-size: 5rem;
    background: transparentize(#47aa79, 0);
}

#section2 {
    display: flex;
    z-index: 2;
    height: 100vh;
    font-size: 9rem;
    font-weight: bold;
    background: #477aaa;
    color: #eee;

    h1 {
        position: absolute;
        transition: all 0.1s linear;
    }
}

Answer №1

Make sure to pass the event parameter to the callback function and utilize it.

$("#my-scrollbar").on("scroll", function(event) {
    console.log(event);
});

The event object will provide you with properties that you can access, such as: event.type

Check out this demonstration: https://codepen.io/aslami/pen/oNBJvpq

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

Customize Vue.js: Disable Attribute Quote Removal for Individual Pages

We have a requirement to turn off the minify.removeAttributeQuotes property for certain pages. This is the content of my vue.config.js: const packageJson = require('./package.json') module.exports = { assetsDir: packageJson.name + &apos ...

w2ui failing to recognize input from HTML form

w2ui seems to be ignoring the input tag's value attribute. How can I make it use the specified value? It works fine with selects. https://i.sstatic.net/pNSey.png Check out the jsfiddle link for more information <div id="form" style="width: 750 ...

List of dropdown options retrieved from SQLite database

I am attempting to retrieve data from an SQLite database table in order to populate a dropdown menu list. My thought process is outlined below. The main issue I am facing is how to integrate the JS function with the HTML section. HTML.html <label ...

CSS styling not appearing on HTML button

I'm attempting to create a login page similar to Instagram using HTML and CSS. However, I'm having trouble styling the button to match Instagram's login page. The button <input type="submit" class="sub-btn"> The CS ...

Using Node.js, add data to the database by clicking a button using JavaScript

I need to update my database with additional data when a specific element is clicked. The element triggers a function that retrieves some information from it, which I want to use along with other details for the database insertion: function insertItem(x) ...

The Chip Component in MUI dynamically alters its background color when it is selected

Currently, I am working on a project in React where I am utilizing the MUI's Chip component. My goal is to customize this component so that it changes its background color when selected, instead of sticking to the default generic color. https://i.sta ...

Can data be retrieved from websites that do not display data in the HTML source code?

Years ago, I utilized Perl and Python to navigate websites by examining the data in the HTML source code. Now, I am eager to embark on a new personal project involving extracting numerical data from: Tables on PredictIt Website Graph elements (x and ...

Is the height set to auto for the image stretching to equal the height of the PNG file?

.q-team-images { width: 6.4rem; height: auto; padding-bottom: 1rem; } Does the CSS styling mentioned above ensure that the image will adjust its height according to the height of its PNG file? ...

What are some ways to implement a pre-execution step, such as an interceptor, before Nextjs runs getStatic

When working with getStaticProps and getServerSideProps in Next.js, I need to intercept and add common header properties to all request calls that are executed server-side. axios.interceptors.request.use(function (config) { // Perform actions before ...

Incorporating rounded corners to an embedded YouTube video

Check out this JSFiddle link. The border-radius property appears to be working correctly at first, but then the rounded corners suddenly disappear shortly after loading. Is there a way to apply rounded corners to YouTube videos that are embedded on a webp ...

The Vue backdrop is hiding the Bootstrap modal

After attempting to integrate a modal into a component, I encountered an issue where the backdrop appears in front and the modal is hidden behind it as shown below. I have reviewed all the position CSS properties within the parent components but could not ...

How can Next-auth handle redirection for 401 errors?

Currently, I am utilizing Next-auth in combination with rtk query. My goal is to configure the application so that whenever a request results in a 401 unauthorized error, the page will automatically redirect to the login page. How can this be achieved? I ...

Can CSS be used to generate a grid or error image in Internet Explorer?

Can an image like this be created using CSS in Internet Explorer? I attempted to use filter: progid:DXImageTransform.Microsoft.gradient, but it was unsuccessful. ...

Retrieving data synchronously from a Promise with Angular

I am looking to display the product history by retrieving the id of the product from the ActivatedRoute.params. In the ngOnInit method, I need to fetch all the historical records of the product and store them in a variable. Afterwards, I want to merge the ...

Is it possible to reorganize several divs for mobile screens?

My setup is quite intricate. I have a layout with 2 rows consisting of three divs each on larger screens. It looks something like this: <div class="row row-1"> <div class""square">square 1</div> <div class"&qu ...

Ditch the UpdatePanel for JQuery

Currently, I am utilizing UpdatePanel to trigger a button click event asynchronously on a webpage. This event calls a method in a separate class that generates an XML file as the output. I am curious if there is a JQuery alternative to achieve the same f ...

Card flip animation using RotateY is experiencing delays in loading

While experimenting with jQuery and CSS3 animations, I encountered a strange issue. When hovering over the card or focusing on the CCV field in my pen, there is a delay in the color transition when the card flips over. It almost seems like it's loadin ...

Traversing a JavaScript object and saving variables into a string

I am facing an issue with storing values within a JavaScript object notation based on the field selected by the user. While I can store the value in a string separated by commas, when the element I'm trying to access is an array, I receive [object obj ...

Is there a way for me to determine the component I was in?

Currently, I am utilizing vue js for a project where I have draggable component items. These components are generated using a for loop to display them. My question is, how can I detect which component I am currently on when I click on it? Here is a snippe ...

How can you find the "et-custom-css" section in WordPress?

One of the challenges I'm facing with my WordPress page is that some CSS classes are located under <style type="text/css" id="et-custom-css">. Additionally, there is a comment at the top of the CSS saying: /* - - - - - - Additional page info - ...