Enhancing HTML "range" element with mouse scroll functionality for incrementing values in step increments

I'm working on developing a scroll feature that operates independently from the main window's scrolling function. I aim to trigger specific events in the primary window based on interactions with this separate scrollbar.

The only solution I could come up with was to create a vertical input element using type="range".

Here is what I have achieved so far (a small slider displayed on the right side of the window): https://jsfiddle.net/xerxes3117/3v1xdjse/4/

HTML:

<p>
    <input class="slider" type="range" min="0" max="25" step="1" value="0" orient="vertical">
</p>

CSS:

p {
        display: inline-block;
    }

    .slider {
        -webkit-appearance: none;
        width: 270px;
        height: 8px;
        background: #d3d3d3;
        outline: none;
        opacity: 0.7;
        -webkit-transition: .2s;
        transition: opacity .2s;
    }

    .slider::-webkit-slider-thumb {
        -webkit-appearance: none;
        appearance: none;
        border-radius: 50%;
        width: 5px;
        height: 8px;
        background: #283e3e;
        cursor: pointer;
    }

    input[type="range"] {
        transform: rotate(270deg) translate(-140px,480px);
    }

JS:

// Script for creating bars and labels

// On change event for updating styling

Currently, I am encountering two issues with this custom slider:

  1. Whenever there is an event (drag, click, scroll), I want the slider to move by just one step. For example, if I click at any position within the slider, it should advance or regress by a single step rather than jumping directly to the clicked spot.
  2. At present, the slider moves only when clicked and dragged, but not when scrolled (using the mouse wheel). I am looking to enable movement through scrolling as well.

If you know of any existing projects or demos showcasing these functionalities, please share them! Additionally, feel free to suggest alternative approaches aside from utilizing the input type="range" element.

Answer №1

Take a look at the newly updated JS Fiddle. You can now utilize the d3.zoom event on the svg to adjust the current step.

JS Fiddle

 //Defining width and height
 var w = 600;
 var h = 250;
 var curentStep = 0
 var dataset = [{
     key: 0,
     value: 5
   }, 
   {
     key: 1,
     value: 10
   }, 
   {
     key: 2,
     value: 13
   },
   // Dataset now consists of objects with keys and values.
 ];

 var xScale = d3.scaleBand()
   .domain(d3.range(dataset.length))
   .rangeRound([0, w])
   .paddingInner(0.05);

 var yScale = d3.scaleLinear()
   .domain([0, d3.max(dataset, function(d) {
     return d.value;
   })])
   .range([0, h]);

 var key = function(d) {
   return d.key;
 };

 function zoomFunction() {
   if (d3.event.sourceEvent.deltaY > 0) {
     if (curentStep > 0) {
       curentStep--
     }
   } else {
     if (curentStep < 25) {
       curentStep++
     }
   }
   stepChange()
 }
 var zoom = d3.zoom()
   .on("zoom", zoomFunction);

 var svg = d3.select("body")
   .append("svg")
   .attr("width", w)
   .attr("height", h)
   .call(zoom);

 svg.selectAll("rect")
   .data(dataset, key)
   // Code for creating bars...
   
 svg.selectAll("text")
   .data(dataset, key)
   // Code for creating labels...

 function stepChange() {
   // Functionality related to changing steps...
 }

 d3.select("input")
   .on("change", function() {
     // Update styling when input changes...
   });

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

Tips for aligning a div below another div nested within a separate container

Can I position div#d2 directly beneath the div#d1 container according to the code below, instead of positioning it outside the height of the wrapper? #wrapper { height: 100%; display: flex; background-color: steelblue; align-items: center; min ...

Utilizing React Material UI for form validation with error handling and informative helper text

I recently created a form in which I needed to validate the inputs. During my research, I came across the material UI library that has an attribute called error boolean, and another attribute called helperText for the TextField input of the form. However ...

Position an element with absolute positioning to the right edge of a relative element

I have a situation where I need to align the end of a position absolute element with the end of a relative element, but the relative element's width is not fixed and may vary based on content. This scenario arises as I am creating a custom dropdown m ...

Tips for creating a POST request using mongoose in NextJS version 13.4

Currently, I am faced with the challenge of executing a POST request using mongoose in NextJS. In my project structure, I have three key files: lib/dbConnect.js, models/User.js, and app/new/route.ts. As defined, app/new/route.ts is responsible for handling ...

Tips for updating VUE's main.js file to incorporate the routers/index.js configuration

What is the reason for the difference in syntax between the VUE UI main.js code generated by CLI/3 and the older version, and how does it function? What are the various components of the new syntax and how do they work? sync(store, router) // for vuex-rou ...

Having trouble getting the CSS 3 Spin feature to work?

Using webkit for previewing in chrome. The spinning circles I created are not working properly (definitely not an HTML issue.) #loader-wrapper { position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: 1000; } #loader { display: inline-bl ...

Issue with React-Route not displaying components

Below is the code snippet from my app.js file: <Router> <Header title="My Todos List" /> <Routes> <Route path="/about" element={<About />} /> <Route path="/" ...

Comparing AngularJS and Node JS in serving web pages, which is better?

Currently, I'm in the process of learning how to develop a web using angular and node JS. One aspect that I am struggling with is determining where to acquire the URLs for links. After doing some research on stack overflow and various tutorials relate ...

Why does Socket.IO seem to be registering two clients instead of just one when there is only one connection

When using my app, the user first lands on the home screen where they can select their username. They then proceed to another page and from there, navigate to the room entry page. The issue I'm facing is with a specific section of my code that update ...

HTML button failing to connect with CSS stylesheet

I am currently teaching myself CSS and using W3schools for guidance. Recently, I added a button to my website that redirects users to another page upon clicking. Everything functions correctly, but now I want to style the button using CSS. However, despit ...

What is the best way to utilize mapping and filtering distinct values in an array using TypeScript?

What is the best way to filter and map distinct elements from an array into another array? I've experimented with various methods but keep encountering a syntax error stating "Illegal return statement". My objective is to display only unique items f ...

What happens when browsers encounter unfamiliar at-rules?

CSS at-rules have been part of CSS since the days of CSS2. As CSS evolves with new specifications like @supports, it's interesting to see how different browsers handle unsupported rules. Do major browsers simply ignore unrecognized rules, or do they f ...

Guide on how to return a JSON result as a Dictionary instead of an Array using Express.js

I need to format my response as a dictionary with specific key-value pairs, like so: { "id": 5928101, "category": "animal welfare", "organizer": "Adam", "title": "Cat Cabaret& ...

Tips for creating a vertical drawer using jQuery and CSS

Hello, I am currently working on developing a drawer component using Ember.js. If you want to view the progress so far, feel free to check out this jsbin http://jsbin.com/wulija/8/edit My goal is to have the drawer look like the following initially: +--- ...

The concept of recursively exporting modules in Node.js modules

Looking for a way to recursively export all .hbs files in a NodeJS 14+ project main JS. I attempted the following: module.exports = () => ({ partial : __dirname + "/../partial/**.hbs", helper : __dirname + "/../helper/*.js" } ...

Top strategies for efficiently managing the loading of extensive PHP pages using Jquery, Ajax, HTML, and other tools

Hey there, I hope you're doing well in this new year. I've been working on a project that creates a "league table" using a large amount of data, similar to those seen in sports like football. The backend is built in PHP to process the data and d ...

The callback for the Ajax request failing before entering the webmethod function

Below is the Ajax request I am using: $.ajax({ type: "POST", url: "ProductDetail.aspx/AddCart", data: '{productId:' + 4 + ',productTypeId:' + 0 + ',quantity:' + 1 + '}', ...

Placeholder text missing in Internet Explorer 11

There seems to be a problem with the placeholder text not showing up in Internet Explorer 11 when using AngularJS. It displays correctly on all other browsers and I have not made any changes to the CSS that could affect it. I even tried disabling all style ...

How can I prevent an endless loop in jQuery?

Look at the code snippet below: function myFunction(z){ if(z == 1){ $(".cloud").each(function(index, element) { if(!$(this).attr('id')){ $(this).css("left", -20+'%'); $(this).next('a').css ...

Looking for a feature where users can easily update their profile using an interactive edit button

I'm currently working on a website project and one of the features I'm tackling is the user's profile page. My objective is to create an edit button within the page that allows the user to modify their name, username, email, and update their ...