Conceal/Reveal the visibility of the webkit scrollbar when scrolling

I'm attempting to create a unique user experience where the scrollbar is initially hidden using opacity. Then, when the user interacts with the page by scrolling or hovering over the scrollbar, it fades in smoothly thanks to CSS transitions. Finally, after a period of inactivity following scrolling, the scrollbar should fade out once again.

Here's the code snippet:

/* CSS */

::-webkit-scrollbar
{
    opacity: 0;
    -webkit-transition: opacity .3s ease-in-out;
    transition: opacity .3s ease-in-out;
}

::-webkit-scrollbar:hover,
.scrolling::-webkit-scrollbar
{
    opacity: 1;
}

/* JS */

$(document).ready(function(){

    var scrollingTimeout = setInterval(function(){
        $('html').removeClass('scrolling');
    }, 1000);

    $(window).scroll(function(){
        clearInterval(scrollingTimeout);
        $('html').addClass('scrolling');
    });

});

However, I've encountered an issue where the opacity doesn't seem to take effect as expected. Even though the style is being applied according to the web inspector, the scrollbar remains visible regardless of whether the scrolling class is added to the HTML tag.

Any suggestions on what might be causing this problem?

Answer №1

If you're looking to enhance scrolling on your website, consider giving Custom Scrollbar Plugin a try. This jQuery plugin offers a cross-browser solution that leverages native browser scrolling while allowing for full CSS customization. Check out the demo examples provided, particularly the Mac OS X example, and experiment with adding transition effects through CSS.

To implement the scrollbar functionality within your document, ensure that the html/body elements have height/width set to 100% and overflow set to hidden. Then, enclose your page content within a DIV element with height/width also set to 100% and overflow set to auto. Finally, apply the scrollbar to this DIV element. For optimal visibility during scrolling, especially on touch devices, utilize the onScroll callback to dynamically add a class to the container or wrapper element.

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 refresh the content in a table on all HTML pages?

I'm a new developer with a website that includes over 100 pages, each containing HTML tables. Is there a way to update all table content at once without manually editing every single page? All pages have links inserted in the table that need to be u ...

"Discover the process of retrieving data from MySQL and integrating it into a PHP/HTML form using a single

After receiving the result, I noticed that I had created two different profiles for each person, but the same profile details are appearing for both individuals. For example, Sam and John have unique profile details, but when I view Sam's profile, it ...

I am interested in creating a ranking system in JavaScript using JSON data based on points

I have a desire to create the following: var users = {jhon: {name: 'jhon', points: 30}, markus:{name: 'Markus', points: 20}}; // I want it to return like this 1. Jhon with number of points: 30 // 2. Markus with number of points: 20 ...

How to locate and interact with the submitName element using Selenium WebDriver

Is there a way to access an input text element with a dynamic id, no name, but has the attribute submitName using Selenium web driver? The document contains multiple elements and I need to retrieve 4 of them. <input class="mandy" id="ms__id7" submitNam ...

Concern regarding the duration setting in the date-picker

Is there a specific "campaign duration" rule where you must select a date between the first and last day of the month? If you choose a date outside of this range, such as a date from the next month, the Backend API will return an "Input param error." Curr ...

A method to eliminate the mouse-over effect following the selection of an input box

Currently, I am utilizing Angular and encountering three specific requirements. Initially, there is an input box where I aim to display a placeholder upon pageload as 'TEXT1'. This placeholder should then toggle on mouse hover to display 'TE ...

Creating a responsive contact form using Javascript

I have a question regarding making a contact form responsive with javascript. I am still new to JavaScript, but I consider myself at a mid-level proficiency with HTML and CSS. The issue I am facing is that I recently registered with a third-party contact ...

Angular Update Component on Input ChangeEnsuring that the component is automatically

<div class=" card-body"> <div class="row"> <div class=" font-icon-list col-lg-2 col-md-3 col-sm-4 col-xs-6 col-xs-6" routerLinkActive="active" *ngFor="let subject of subjects"> <div class=" fon ...

What is the best way to add query parameters to router.push without cluttering the URL?

In my current project, I am using NextJS 13 with TypeScript but not utilizing the app router. I am facing an issue while trying to pass data over router.push to a dynamically routed page in Next.js without compromising the clarity of the URL. router.push({ ...

Implement a dynamic table in real-time with jQuery AJAX by fetching data from JSON or HTML files

Hey @SOF, I'm trying to add an auto-update feature to my school grades webpage using jquery and ajax to refresh the data when new information is available. I also want to create a "single view" for classes. The challenge I'm facing is getting t ...

Aligning the .left position to make the border of a <div> synchronized

When working on my Jquery program, I encountered an issue with borders not aligning properly within the container. Specifically, in the execution (where the container is represented by a white box), the left border extends beyond the position().left proper ...

What is the best way to maintain the previous input value on page refresh in Vuejs?

In my development project, I am utilizing the Laravel and Vue.js technologies. I am facing an issue where I need to set the input value to its previous old value when either refreshing the page or navigating back to it in a Vue dynamic component. Here is ...

Tips for organizing my data upon its return into a more efficient structure

I need to restructure API data that is not optimized in its current format Unfortunately, I am unable to ask backend developers to make the necessary changes, so I am exploring ways to clean up the model locally before using it in my Angular 2 application ...

Using IMG HTML tags in PHP embedded within JavaScript code

Is there a way to successfully add an IMG src tag in JavaScript to pass the image source to a JavaScript variable 'content' and then have it passed to a PHP variable '$html'? I've attempted this but keep encountering an 'unide ...

What is the process for extracting dates in JavaScript?

I need help extracting the proper date value from a long date string. Here is the initial date: Sun Aug 30 2020 00:00:00 GMT+0200 (Central European Summer Time) How can I parse this date to: 2020-08-30? Additionally, I have another scenario: Tue Aug 25 ...

Bizarre error when injecting Factory into Controller in AngularJS

After scouring through countless posts on various forums, I have yet to find a solution to my unique problem. I find myself in a peculiar situation where I am trying to inject a Factory into a Controller, and despite everything appearing to be in order, i ...

Retrieving Axios error codes within an interceptor

How can error codes like ERR_CONNECTION_REFUSED (indicating the API server is down) and ERR_INTERNET_DISCONNECTED (indicating the local network is down) be accessed when using response interceptors with axios in client-side JavaScript, React, etc.? While ...

Organizing content with divs in HTML/CSS

I've incorporated a theme in my designs where there is a blue bar beneath the text, like shown in the images below https://i.sstatic.net/TuVGd.png https://i.sstatic.net/CCJRo.png Currently, I've been structuring my HTML for these bars in the f ...

The jQuery's load function appears to be malfunctioning

$toolTip_inner.load('ajax/fetchUser_data.php',{ id: $tooltipText }); I am attempting to load the content of a PHP file into the toolTip_inner element while passing some parameters. The fetchUser_data.php file executes a MySQL statement and retr ...

HTML Code for Tracking Facebook Friends' Likes on a Page

I am looking to show the number of friends who have liked a page in HTML. Can someone please guide me on this? I am aware that we can get the page likes using a simple URL, but I specifically want to know how to retrieve the count of friends who liked a ...