Creating a Spotify-inspired overlay scrollbar on a website using a combination of CSS and Javascript techniques


UPDATES (4th March, 2024):

  1. I have revised my question to eliminate unnecessary code and wording. It should now be clearer and more readable.
  2. I've learned that Spotify's scrollbar was created using javascript


I'm looking to create a scrollbar with the following two (2) characteristics:

  1. Overlays over the content of the div
  2. Features a transparent Scrollbar-track

In previous years, utilizing 'background: transparent' and 'overflow: overlay' worked but they are now deprecated.

I've searched for alternative methods through various sources but haven't found a solution yet.

While using Spotify, I noticed their customized scrollbar which had a transparent track - exactly what I'm aiming for.

Here's an image of the Spotify-styled scrollbar:

Image of This is the image of the Spotify Scrollbar

I've included a snippet below to demonstrate what I'm trying to accomplish. I've created three child divs in the snippet, each with different background colors, within a parent div with a scrollbar.

The transparency effect is working, however, I'm struggling to get the scrollbar to overlay the child divs inside the parent div.

I'd appreciate any guidance on achieving this overlaying effect using:

  1. CSS alone
  2. OR by incorporating javascript.

html,
body {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

 ::-webkit-scrollbar {
  width: 25px;
  border: 2px solid #a5393900;
  border-radius: 10px;
}

 ::-webkit-scrollbar-track {
  background: transparent;
}

 ::-webkit-scrollbar-thumb {
  width: 5px;
  background: #f2f2f282;
  background: #f2f2f28f;
  border-top-right-radius: 10px;
  border-bottom-right-radius: 10px;
}

body {
  width: 100%;
  min-height: 100vh;
  /* ---- > depracated <-------- */
  overflow: overlay;
}


/* ----- House div needed to center the Parent ------ */

.house {
  width: 100%;
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
}


/* --- Parent ----- */

.parent {
  width: 450px;
  height: 450px;
  padding: 15px;
  background-image: linear-gradient(to top, #ff00ff, #16dc7c);
  border-radius: 10px;
  overflow: hidden;
  overflow-y: scroll;
}


/* ----- CHildren (All) ---- */

.child {
  width: calc(100% - 50px);
  /* width: 100%; */
  height: 200px;
  color: #ffffff;
  padding: 10px 65px 0px 60px;
  z-index: 10;
}


/* ----- First child ------ */

.child.ch1 {
  background-color: #264cb3;
}


/* ---- Second Child ----- */

.child.ch2 {
  background-color: #8728a7;
}


/* ---- Third Child ---- */

.child.ch3 {
  background-color: #ad9521;
}
<div class="house">
  <div class="parent">
    <div class="child ch1">
      The scrollbar should overlay this div
    </div>
    <div class="child ch2">
      The scrollbar should overlay this div
    </div>
    <div class="child ch3">
      The scrollbar should overlay this div
    </div>
  </div>
</div>

Answer №1

Spotify has implemented a custom scrollbar, as shown in this image. To replicate this functionality, you will need to utilize Javascript.

Alternatively, here is a method using only HTML and CSS:

<!DOCTYPE html>
<html>
  <style>
    html,
    body {
      margin: 0;
      padding: 0;
    }

    body {
      overflow: overlay;
    }

    #main-container {
      width: 100%;
      height: 100%;
      overflow-y: scroll;
    }

    #wrapper {
      width: 500px;
      height: 500px;
      padding: 4px;
      background-image: linear-gradient(to top, blue, purple);
      border-radius: 10px;
      overflow: hidden;
    }

    #box {
      width: 100%;
      height: 800px;
    }

    ::-webkit-scrollbar {
      width: 10px;
      height: 10px;
    }

    ::-webkit-scrollbar-thumb {
      background: rgba(20, 20, 20, 0.507);
    }

    ::-webkit-scrollbar-track {
      background: transparent;
    }
  </style>

  <body>
    <div id="wrapper">
      <div id="main-container">
        <div id="box">This is my content</div>
      </div>
    </div>
  </body>
</html>

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

The modal remains visible

Has anyone encountered a problem with hiding a Bootstrap modal based on form validation in JavaScript? I'm facing an issue where the submit function is not executed when I click the button. I've attempted using onsubmit=validateForm(), but it doe ...

Using environmental variables in Nuxt 3 outside of component setup scripts can be easily achieved by accessing the variables directly

I have stored different API URLs in my .env file, specifically for development and production environments. Here is how I access these URLs: const isProdEnv = process.env.NODE_ENV === 'production' const DEV_API_URL = "https://example-stage.h ...

Strange border appears in HTML email table for specific sizes of screens

I am working on an HTML email and encountering a strange issue. When I view the email in Chrome with responsive mode enabled, there is a faint border on some of the cells. I cannot identify the cause as none of the cells have borders, and the issue only ap ...

Discover the trick to capturing the back button and dynamically refreshing the webpage with ajax!

I am currently facing an issue with a dynamically updating web page where I need the browser's "back" button to trigger a function for refreshing data instead of navigating back a page. I have managed to trap the "back" button using the following code ...

methods for sorting firestore data in react on client side

Fetching data from firestore and applying filters const [projects, setProjects] = useState([]); const fetchData = (sortBy = "NAME_ASC") => { const unsubscribe = firebase .firestore() .collection("projects") ...

Updating all the direct components within the corresponding category with jQuery

Here is the HTML content I am working with: <li class="info"> info<li> <li class="other"> info<li> <li class="other"> info<li> <li class="Error"> error<li> <li class="other"> error<li> < ...

Iterate through each image within a specific div element and showcase the images with a blur effect applied

I have a div with multiple images like this: <div class="am-container" id="am-container"> <a href="#"><img src="images/1.jpg"></img></a> <a href="#"><img src="images/2.jpg"></img>< ...

Explore the possibilities of integrating react-native-fs into your create-react-native-app project built on Expo

I have been working on implementing react-native-fs into my app for file uploading purposes. I carefully followed the installation steps mentioned in the documentation, imported the required modules, and added the following code snippet for testing: compo ...

What is the procedure for setting up a Node application to listen on a specific host entry domain

Let's say I've added three entries to my /etc/hosts file: 127.0.0.1 domain1.com 127.0.0.1 domain2.com 127.0.0.1 domain3.com Now, I want my three node applications to listen for requests on these domains that I've created. How can I make th ...

Having trouble pinpointing the source files that are loading .js in the <head> section of my Magento website

My console is showing me three 404 errors related to missing .js files in the head section of my website. Even though I don't actually need these files, I want to stop receiving the 404 errors as they are affecting my analytics and SEO. The files caus ...

JavaScript's speciality - altering the Jquery fade in and fade out effect on Firefox browsers

Utilizing Jquery, I implemented a feature on a table where moving the mouse over a row changes its color. The Javascript code was specifically designed for IE7 and works flawlessly there. However, when tested in Firefox, the text fades along with the backg ...

Tips for creating emissiveMap lighting exclusively in dimly lit spaces using three.js

Using three.js, I am able to render the earth with textures and add an emissive texture for city lights. However, I am facing a problem where even the light areas of the earth emit city lights. For example: https://i.sstatic.net/hZ1Cr.png Is there a way ...

Error Message: Initial Connection Failed - Unable to Establish Connection with MongoDB Server

After trying to execute a GET request from my mlab database, I encountered the following issue: (node:47578) UnhandledPromiseRejectionWarning: MongoNetworkError: failed to establish a connection with the server [ds157439.mlab.com:57439] on the initial atte ...

Oops! It seems like you've stumbled upon a 404 error on Django

I need to retrieve the price value immediately after a product is selected in the sale form. The sale form includes fields for price, quantity, and product. Once a user selects a product, the price of that product should populate the input box for price. T ...

Combining JavaScript JSON objects with corresponding parameters

I'm struggling to find a solution for merging two JSON objects. Despite searching for answers, I haven't found any that have been helpful. My goal is to compare two objects and if there's a match, add an attribute as a marker to the first ob ...

SyntaxError: Unexpected symbol

I have an issue with the following code: let op = data.map(({usp-custom-90})=> usp-custom-90 ) When I run it, I encounter the following error: Uncaught SyntaxError: Unexpected token - I attempted to fix it by replacing the dash with –, but t ...

What are the steps to conducting a search on mongodb?

My document list is shown below [{"userId": "1", "text": "National security is of utmost importance"}, {"userId": "2", "text": "We must ensure a strong defense while upholding civil ...

Countdown timer feature and auto-submit function for your website's page

Currently, I am working on an online exam project that requires the page to be automatically submitted after 10 minutes, regardless of whether the user clicks on the submit button or not. Additionally, I want to include a countdown timer to display the r ...

Tips for concealing a chosen alternative from the menu of options when utilizing mat-select

I am currently working with the latest version of mat-select, version 16. I have a requirement where, when a specific option is selected and the select drop-down is clicked again, that selected option should not appear in the options list. Below is the HTM ...

Tips for decreasing the width of your HTML or body content using media queries

I am struggling to adjust the width of my desktop view using a media query. My most recent attempt looks like this: @media (min-width: 992px) and (max-width: 1199.98px) { html, body { max-width: 80%; } } However, this code seems to have no ...