Building a geometric slider using HTML5, CSS3 and jQuery

Currently, I am attempting to construct a triangular slider that resembles the one shown in the example:

While I can generate the triangle visually, the technical aspects like enabling node dragging, restricting its movement within the triangle boundaries, and calculating values based on the node's position elude me at this moment.

If anyone is aware of a plugin that can assist with this functionality, kindly share it. Alternatively, any guidance or support would be greatly valued.

Answer №1

To drag the node, utilize Jquery.UI draggable and include a drag event that returns false if the point falls outside the triangle's bounds (refer to: for the algorithm). It is essential to ascertain the coordinates of the triangle's vertices (http://jsfiddle.net/dLzWr/) .

//retrieve the top point of the triangle
function getTopPoint(t){
    var pos = t.offset();
    //include border dimensions in the offset calculation
    var leftBorder = parseInt(t.css("border-left-width"),10);
    var topBorder = parseInt(t.css("border-top-width"),10);
    pos.left += leftBorder;
    pos.top += topBorder;
    return pos;
}

//fetch the bottom left point of the triangle
function bottomLeftPoint(t){
    var top = getTopPoint(t);
    top.top += parseInt(t.css("border-bottom-width"),10);
    top.left -= parseInt(t.css("border-left-width"),10);
    return top;
}

//obtain the bottom right point of the triangle
function bottomRightPoint(t){
    var top = getTopPoint(t);
    top.top += parseInt(t.css("border-bottom-width"),10);
    top.left += parseInt(t.css("border-right-width"),10);
    return top;
}

In examining the fiddle, you can calculate the distance between each vertex and the current point during the draw event, using this information to determine the values.

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

Showcase two featured WooCommerce categories on the homepage

On my main page, I am looking to display two categories, mobile and laptop, simultaneously. However, the code I'm using only shows one of the categories. Any assistance would be appreciated. Thank you! <?php $products= new WP_Query( array( ...

What is the method to prevent the background image from refreshing when clicking on the navbar?

I have designed a webpage with a navigation bar. However, when I click on a button in the navbar, the image refreshes and does not display correctly. I attempted to show different pictures when each button in the navbar is clicked. Each button should disp ...

Getting .data() using jQuery's $.get (or $.ajax) function is a simple and efficient process

Within our website, the <body> tag contains a range of data-*="*" attributes: <body data-someData="someValue" data-someOtherData="someOtherValue"> My goal is to retrieve the values of these attributes while navigating through different pages. ...

What is the best way to incorporate an AJAX GET request into an HTML element?

Currently, I am attempting to execute a JavaScript code that will convert all <a></a> elements found within another element <b></b> (the specific name in the HTML) into links that trigger an HTTP get request. However, the code I hav ...

The functionality of Kendo Autocomplete is currently experiencing issues when used in Mozilla Firefox

Currently, I am implementing the Kendo Autocomplete feature on a textbox to retrieve a list of cities. The functionality works perfectly fine on Chrome, but when I tested it on Mozilla, the list flickers - appearing and disappearing rapidly. Below is the ...

Ensuring your image matches the size of the containing div element

I am trying to create a navigation bar in the footer of my website using images. The footer should take up 10% of the total screen, and the images should also be contained within that 10%. However, I am having trouble with the images not scaling properly a ...

Placing text at the bottom of a backdrop image

Looking for a way to position text at the bottom of a background image? Here's how you can do it: <div style="background-image: url('http://www.hdwallpapersinn.com/wp-content/uploads/2013/03/1325120512b60-45927-1.jpg'); height:100px"> ...

Troubleshooting Issue with jQuery Data Link's Handling of Select Lists

Using a basic address form with the innovative Data Link plugin, I have set up a simple create/edit process that involves an ajax call to populate the form if an ID exists, or display a blank form if not. dataComplete : function(data){ $self.step1 ...

I'm having trouble with Gutters GX and GY not functioning properly in Bootstrap, HTML, and CSS

I attempted to incorporate gutters into my Bootstrap grid layout, however, they are not showing up as expected. I am following the guidelines provided on the Bootstrap documentation, but for some reason, the gutters are not appearing. <!DOCTYPE html> ...

What is the best way to display an error message when the JSON result is unsuccessful?

When using Ajax, the success part always executes. However, if an error occurs, I want to display an error message instead of running the normal process. If a discount code is present, I need to show/hide certain div elements along with the code and then r ...

Toggle a div using jQuery with a distinctive identifier

I need to display all products that a client has ordered from the database and I want to be able to show/hide them when clicking on a specific div element. http://prntscr.com/7c5q6t Below is my PHP code which displays all the ordered products: <td cla ...

Angular: Compilation of SCSS/SASS results in unexpected whitespace issues

I am encountering an issue with whitespace being added to the CSS after compiling a *.scss file in my Angular 7 project. This unwanted whitespace is causing incorrect results in the UI. To replicate the problem, you can visit... ...and copy and paste the ...

Having trouble with displaying the logo on the navigation bar (using bootstrap and django)?

Hello, I am struggling to include a logo in my navbar and it's not being displayed. Despite researching similar queries from others, I still can't figure out why the image won't show up. I'm uncertain whether the issue lies within my co ...

Bootstrap 5 Hamburger Icon Toggler for Navigation Menu

After opening the code, I am unable to close it properly. I need to find the solution to this issue. Can someone identify what is causing this problem? <nav class="navbar navbar-expand-lg navbar-light bg-light"> <div class="co ...

Using Javascript, create a loop that navigates between two different pages and add a timer on one of them

How can I create a while loop that spans across 2 HTML pages or use a prompt to ask a question? If the wrong answer is provided, I would like to be redirected to another HTML page which will display for 5 seconds before returning to the prompt. This is my ...

Interact with an element on one page and watch as it dynamically affects another element on a separate page using J

Is it possible to use jQuery to click a button on one page (index1.html) and change the color of text on another html page (index2.html)? I've tried various methods, but none seem to work due to the need to refresh the second page in order to view ch ...

What is the best way to determine if a child div exists within a parent div?

Is there a way to determine if any div exists within the parent div? In my current scenario, I am adding two divs inside the parent div like this. $('#realTimeContents').append("<div style='width:22%; float: left; font-size:18px; line- ...

Ways to store information in variables and use it across different blocks in Cypress

Is it feasible to store data in variables and reuse them in other blocks within Cypress.io? For instance, imagine I have a unique name for a device. I aim to retrieve this information and then verify if the title in a new window includes that particular de ...

The appearance of Google Fonts varies between google.com and my own website

After experimenting with Google Fonts, I made a discovery that left me puzzled: The font displayed in my custom HTML file is not the same as the one on the Google Fonts website. Specifically, the font size appears to be significantly different (color v ...

Invalid JSON syntax: found an unexpected token, the letter

JSON.parse() doesn't seem to be functioning properly within my code, and I'm unsure of the root cause. JavaScript Code: var obj = JSON.parse(this.responseText); console.log(obj.status + " " + obj.type); if (obj.status == "success") { documen ...