Issue with Vue custom range slider where cursor position is not accurately displayed

I recently developed a unique input range slider using Vue.js.

While most aspects of the slider are functioning correctly, I have encountered an issue with the cursor position not aligning properly while sliding the range slider.

  • Ideally, the cursor should follow the green thumb of the slider accurately.
  • However, what actually happens is that the cursor appears to be ahead of the thumb during sliding actions.

To keep things concise, I have excluded certain details in this query:

You can preview the slider without the endpoint here (expect some console errors):

The code snippet for the range input is provided below. It showcases how I bind the style with values obtained from an endpoint to compute the width and transform properties. While these bindings function correctly, the cursor positioning issue remains unresolved.

<div class="range-container">
                            <div
                                class="wrap"
                                :class="{ invalid: isExceedMonth }"
                            >
                                <input
                                    type="range"
                                    class="range2 calc-range"
                                    value="value"
                                    :min="duration.min"
                                    :max="duration.max"
                                    v-model="duration.amount"
                                    @input="onChange2"
                                />
                                <div class="track2">
                                    <div
                                        class="track-inner2"
                                        :style="{ width: duration.amount == duration.min || isExceedMonth ? `${0}%` : `${ duration.amount / (duration.max/100) }%` }"
                                    ></div>
                                </div>
                                <div
                                    class="thumb2"
                                    :style="{ left: duration.amount == duration.min || isExceedMonth ? `${0}%` : `${ duration.amount / (duration.max/100) }%`, transform: duration.amount == duration.min || isExceedMonth ? `translate(-${ 0 }%, -50%)` : `translate(-${ duration.amount / (duration.max/100) }%, -50%)` }"
                                ></div>
                            </div>
                            <div class="calc-flex mt-30" v-cloak>
                                <p class="min">{{ duration.min }}</p>
                                <p class="max">{{ duration.max }}</p>
                            </div>
                        </div>

Additionally, by inspecting the code through dev tools and removing track2 and thumb2, leaving only the input (opacity set to 1 for testing), I noticed that the thumb and cursor behavior corrected itself. However, the color distinctions (yellow and gray) were lost in this altered state. Why does my custom code introduce this particular issue?

Answer №1

Upon further review, it appears there was a small error in my initial calculation:

The original code snippet was as follows:

left: loan.amount == loan.min || isExceedMoney ? `${0}%` : `${ loan.amount / 100 }%`

I have now made the necessary adjustment to achieve the correct result:

left: loan.amount == loan.min || isExceedMoney ? `${0}%` : `${ (loan.amount - loan.min) / (loan.max - loan.min) * 100  }%`

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

Illustration next to content featuring a heading and a paragraph

I've been working on a website design and trying to position text next to an image. It seems like a simple task, but I'm struggling to make it work. Here's an illustration of how I want the layout to look: So far, here is the HTML code I&a ...

Issue with maintaining fixed space above navbar in HTML/CSS code

I'm struggling to make my navbar sticky on my website without any space above it. Can someone help me with this issue? Here is the URL to my site: My CSS looks like this: body { font-size: 12px; line-height: 22px; font-family: Arial, H ...

Version 2.2.2 of Vue seems to be having trouble rendering the data onto the View

The current version being used is Laravel 5.2 with Browserify, not Webpack. Everything has been set up as follows: In the resources/js/app.js file: window.Vue = require('vue'); new Vue({ el : '.row', data : { ...

Interface key error caused by the TypeScript template literal

Version 4.4.3 of Typescript Demo Playground Example -- interface IDocument { [added_: `added_${string}`]: number[] | undefined; } const id = 'id'; const document: IDocument = { [`added_${id}`]: [1970] } My Attempts: I made sure that id in ...

The variable is only recognized within the function and not outside of it

Seeking assistance as a newcomer in debugging and implementing code, I have been trying various approaches to pass a base64string into JotForms for generating images in PDF format. Below is the screenshot of the error encountered. View error here The foll ...

The sticky navbar remains fixed only within the initial section of the page

Currently, I am working on a Bootstrap website that is supposed to be a one-page site with a navigation bar at the top. However, I am facing an issue where the navbar is sticky only for the first section and then disappears as I scroll down. How can I make ...

Unable to Display Dropdown Arrow in React-bootstrap

Could someone please explain why the dropdown arrow is not showing up for me? Any help would be greatly appreciated. Here is my current code: import { Col, Row, ListGroup, Form} from 'react-bootstrap' {something.Available > 0 && ( ...

Guidelines for removing a 2D Primitive in processing

I am facing issues with deleting 2D primitives. I attempted to create a rectangle in front of these primitives to conceal them. However, I need to hide them when clicking somewhere, which leads me to believe that the draw() function is overriding the mouse ...

Can the loading of the window be postponed?

I've created a script that displays a message when the user first visits the website. The message then fades out, followed by another section fading in after a short delay. $(window).load(function() { $(".greeting").delay(1500).fadeOut("500"); ...

Full height container with footer

Currently facing an issue with a page I am working on. Here is a snippet of the code: <div id="header"> // header.. </div> <div id="content"> // content where ajax is loaded (should cover at least 100% of the site height) <!- ...

The forEach function selectively bypasses certain objects during the iteration process

I have a task that involves writing a function to process an array of objects containing information and save that data in a JSON file. For instance: let arr = [ { creator: 'Girchi', title: ' ...

Encountering 404 Errors while Attempting to Reach API Endpoint in an Express.js Application Hosted on cPanel

I have a Node.js application running on cPanel, and I'm facing 404 errors when trying to access an API endpoint within my app. Let me provide you with the setup details: Directory Structure: public_html/ server.mjs index.html node_modules ...

Custom hooks in Next.js do not have access to the localStorage object

I've encountered an issue with my custom useLocalStorage hook. It works perfectly fine with create-react-app, but when I try to use it with Next.js, the value in the initial state on line 3 returns undefined. Is there a way to bypass server-side rend ...

Unzipping a .gz file in node.js: a simple guide

I have downloaded a .csv.gz file from a remote server, and I have the content of this file stored as a string. When I console.log it, here is a small sample of what it looks like: }v)tYj8p0eCR l1=6~̵r0c77LU:0g How can I decompress this in Node.js and c ...

Utilizing Jquery and OwlCarousel to showcase a carousel when clicking on individual links

Currently, I am facing an issue with displaying three carousels on my website. I am attempting to show each carousel when clicking on a specific link using jQuery. The problem arises when I apply the CSS property "display: none" to a div containing the ca ...

Combining arrays based on their IDs during the Created() lifecycle event in Vue2, whether they are of equal or unequal lengths

I am in need of some coding advice as I have been unable to find a solution...Possibly a two-part question: When Created(), I want to merge 2 arrays (one being an external Axios API). ''' <template> <div v-for="merged i ...

Desktop display issue: Fontawesome icon not appearing

Having trouble getting the fontawesome icon to display properly on my website. It appears in inspect mode, but not on the actual site itself. Any suggestions on how to fix this issue? import React, { Fragment, useState} from "react"; import { Na ...

Tips for customizing the blinking cursor in a textarea

I am experimenting with creating a unique effect on my website. I have incorporated a textarea with transparent text overlaying a pre element that displays the typed text dynamically using JavaScript. This creates an illusion of the user typing in real-tim ...

Comparing innerHTML in JavaScript: A guide to string comparison

While attempting to filter a table alphabetically, I encountered an obstacle. The x.innerHTML > y.innerHTML concept in this code snippet is perplexing me: table = document.getElementById('myTable'); rows = table.getElementsByTagName('t ...

Incorporate a variable into a string

My task here is to prepend a variable before each specific string in the given text. For example: var exampleString = "blabla:test abcde 123test:123"; var formattedString = "el.blabla:test abcde el.123test:123"; In this case, whenever there is a pattern ...