How to Make Scrollbar Custom Arrows Work on Mobile Devices?


You may have noticed websites with distinctive scrollbars that give them a unique feel and appearance since custom scrollbars are becoming more and more common. A custom scrollbar can simply be implemented in a few different ways. The easiest method will be used in this article, which is CSS.

We employ CSS to enhance the visual appeal of web pages in our applications. Using CSS, we can now change how the scrollbar looks. Let’s see how to make scrollbar custom arrows work on mobile devices.

Making scrollbar custom arrows work on mobile devices

Back in the day, scrollbars on websites could be modified using non-standard CSS attributes like scrollbar-base-color, which you would apply to the element that scrolls (like the ) and do completely awesome stuff. IE abandoned that.

Custom scrollbars are once again available today, although this time WebKit is used. The properties now use the "Shadow DOM" and are vendor-prefixed (for example: -webkit-scrollbar). This has been in existence for a while.

For getting more idea on making the scrollbar custom arrows work on mobile devices, let’s look into the following examples.

Example

In the following example, we are using the webkit-scrollbar for making the scrollbar work on mobile devices and applying CSS to the scrollbar.

<!DOCTYPE html>
<html>
   <body>
      <style>
         div{
            max-width:400px;
            max-height:250px;
            overflow-y: scroll;
            overflow-x: hidden;
         }
         div::-webkit-scrollbar {
            width: 0.5em;
         }
         div::-webkit-scrollbar-track {
            -webkit-box-shadow: inset 0 0 2px rgba(1,1,1,0.4);
         }
         div::-webkit-scrollbar-thumb {
            background-color: #D5F5E3;
            outline: 1px solid #FBFCFC;
         }
      </style>
      <div id="tutorial">
         <img src="https://www.tutorialspoint.com/about/images/about-mini-logo.jpg">
         Tutorials Point originated from the idea that there exists a class of readers
         who respond better to online content and prefer to learn new skills at their
         own pace from the comforts of their drawing rooms.The journey commenced with
         a single tutorial on HTML in 2006 and elated by the response it generated, we
         worked our way to adding fresh tutorials to our repository which now proudly
         flaunts a wealth of tutorials and allied articles on topics ranging from programming
         languages to web designing to academics and much more.
      </div>
   </body>
</html>

When the script gets executed, it will generate an output consisting of an image, some text, and a scrollable display on the webpage.

Example

Considering the following example, where we are using webkit-scrollable to make the content scroll on the webpage along with arrows.

<!DOCTYPE html>
<html>
   <body>
      <style>
         .visible-scrollbar,
         .mostly-customized-scrollbar {
            display: block;
            width: 300px;
            overflow: auto;
            height: 150px;
         }
         .invisible-scrollbar::-webkit-scrollbar {
            display: none;
         }
         .mostly-customized-scrollbar::-webkit-scrollbar {
            width: 300px;
            height: 8px;
            background-color:#7D3C98 ;
         }
         .mostly-customized-scrollbar::-webkit-scrollbar-thumb {
            outline: 1px solid #FBFCFC;
         }
      </style>
      <div class="visible-scrollbar">
         Mahendra Singh Dhoni born 7 July 1981, commonly known as MS Dhoni,
         is a former Indian cricketer and captain of the Indian national team
         in limited-overs formats from 2007 to 2017, and in Test cricket from
         2008 to 2014. He is also the current captain of Chennai Super Kings in
         the Indian Premier League. Under his captaincy, India won the 2007 ICC
         World Twenty20, the 2011 Cricket World Cup, and the 2013 ICC Champions
         Trophy, the most by any captain. He also led India to victory in the 2010
         and 2016 Asia Cup.
      </div>
   </body>
</html>

On running the above script, the output window will pop up, displaying the text along with scrollable arrows that get displayed on the webpage.

Example

Execute the below code and observe how we are going to make a custom scrollable using webkit-scrollable.

<!DOCTYPE html>
<html>
   <body>
      <style>
         body {
            font-size: 15pt;
         }
         ::-webkit-scrollbar {
            width: 14px;
            border: 1px solid blue;
         }
         ::-webkit-scrollbar-button:single-button {
            background-color: fuchsia;
            height: 10px;
            width: 10px;
         }
         ::-webkit-scrollbar-thumb {
            background: maroon;
         }
         ::-webkit-scrollbar-track {
            background: silver;
         }
         ::-webkit-resizer {
            background: olive;
         }
      </style>
      <center>
         <img src="https://upload.wikimedia.org/wikipedia/commons/3/3a/Ducatilogol.png">
         <p>Ducati is a group of companies, best known for manufacturing motorcycles
         and headquartered in Borgo Panigale, Bologna, Italy. The group is owned by
         German automotive manufacturer Audi through its Italian subsidiary
         Lamborghini, which is in turn owned by the Volkswagen Group.</p>
         <br>
         <p>In the 1930s and 1940s, Ducati manufactured radios, cameras, and
         electrical products such as razors. Ducati also made a marine binocular called the BIMAR for the Kriegsmarine during World War II, some of which
         were sold on the civilian market after the war.The Ducati Sogno was
         a half-frame Leica-like camera which is now a collector's item.</p>
      </center>
   </body>
</html>

When the script gets executed, it will generate an output consisting of text along with an image and a custom scrollable applied with CSS that is displayed on the webpage.

Updated on: 20-Apr-2023

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements