Determination of an arc trajectory using JavaScript

I have been trying to figure out how to replicate this effect. The Red arrowhead remains stationary while the background features a curved path. Currently, I am adjusting the background position to give the illusion of the arrowhead moving along the curved path.

Check Out the Red Arrow HERE

My current code has the arrow moving at a 45-degree angle towards the destination. However, my goal is to have the arrow move along that dashed path displayed in the image.

var interval = 100;

var currX = -82;    // Current x position
var currY = -342;   // Current y position

var destX = -750;   // Destination x position
var destY = -850;   // Destination y position

var currentDuration = 0;
var duration = 1800 * 1000;  // Duration

var $bg = $('#flight-wrapper');

var intbg = window.setInterval(function(){
    currentDuration += interval;

    var leftX = destX - currX;  // X pixels left
    var leftY = destY - currY;  // Y pixels left

    var leftDuration = duration - currentDuration;  // Duration left

    var tickX = leftX / leftDuration * interval;    // Pixel offset
    var tickY = leftY / leftDuration * interval;    // Pixel offset

    var newX = currX + tickX;
    var newY = currY + tickY;

    // Ensure it does not overshoot the destination X & Y pixel
    currX = newX <= destX ? destX : newX;
    currY = newY <= destY ? destY : newY;

    if ( currX <= destX && currY <= destY ) {
        window.clearTimeout(intbg);
    }

    $bg.css({
        backgroundPosition: Math.floor(currX) + 'px ' + Math.floor(currY) + 'px'
    });
}, interval);

I would greatly appreciate any help or suggestions in achieving this desired effect.

Answer №1

When looking at the coordinates of a point p = (x_t, y_t) where an arrow is located at time t, it becomes important to determine the numerical tangent of the curve at this specific point p. This information will precisely indicate the direction in which the arrow should be pointing.

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

Pressing a sequence of buttons to meet a requirement using JavaScript

Currently, I have a set of four buttons that trigger an alert message when all of them are clicked. However, I am looking to modify this behavior so that the alert is displayed only when specific combinations of buttons are pressed, such as button1 and b ...

Access a PHP file using XMLHttpRequest to run additional JavaScript code

My main page, referred to as Main.php, contains a button that triggers the display of results from Results.php within a div (divResults) on Main.php. The HTML content "These Are The Results" returned by Results.php is successfully displayed in the divResu ...

Examining a specific element node to see if it contains a certain string

When using PHP Unit with Selenium Server, my goal is to verify if a specific element in an xpath contains a certain string value, like this: <table> <thead></thead> <tbody> <tr> <th>1</th> < ...

The text in the image caption has been drastically reduced along with the size of the image

Currently, I am dealing with the following code: <div style="min-width: 1000px;"> <p> Some text </p> <div class='div_img_left'> <img src="images/sth.png" alt="missing image" style="max-width ...

Guide on sending a JavaScript variable to PHP using AJAX

I am currently utilizing the following JavaScript code to obtain data from a td element when a button is clicked within an onclick event. function rfk(element) { var element = element.parentElement.parentElement; var id = parseInt(element.childre ...

Getting Started with SimpleModal in ASP.NET: A Beginner's Guide

Implementing SimpleModal with ASP.NET I want to express my gratitude to Eric for creating SimpleModal and applaud the demos. They look incredible. I am struggling to grasp how to use it though, seems like I'm missing something here. Apologies in adv ...

Utilizing ng-switch for handling null values or empty strings

Can anyone assist me with this issue? I have a variable called $rootScope.user = {name:"abc",password:"asd"}. When a service response occurs, I am dynamically creating a rootscope variable by assigning it. How can I use ng-switch to check if the variable h ...

Retrieving the text from the img tag of a bs4.element.Tag

I have a question that needs to be addressed. My concern involves a list of bs4.element.Tags, similar to the one illustrated in the image below. The issue at hand is filtering out only the href tags that are preceded by an <img> tag. How can this s ...

Enhance your Select options using Ajax and Jquery by updating based on the value of another Select option

I'm struggling to understand how to dynamically update the options in a second select box based on the selection made in the first one. To achieve this, I am aiming to utilize a predetermined JSON object for the available choices in the second select ...

Implementing a JavaScript confirmation based on an if-else statement

I need to display a confirmation dialog under certain conditions and then proceed based on the user's response of yes or no. I attempted the following approach. Here is the code in aspx: <script type="text/javascript> function ShowConfirmati ...

Combining items from the identical array in pairs using distinct identifiers

I have an array containing double values. const data = [ -0.003,-8.178509172818559E-16, 0.002,-1.3576469946421737E-15, 0.007,-1.2329107629591376E-1] I am looking to utilize these values in react-vis. The necessary syntax for data insertion in react-vis ...

An error occurs when attempting to assign a value to a MUI file TextField

Struggling with setting the value of a MUI Textfield that has type="file" props, resulting in the following exception being thrown: Uncaught DOMException: An attempt was made to use an object that is not, or is no longer, usable Interest ...

Difficulty Intercepting Browser's Back Button Press on Next.js Success Page

Currently, I am developing a Next.js application that includes a success page for users who have completed a payment transaction. My goal is to prevent users from navigating back to the payment page by intercepting the back button press and redirecting the ...

Calculating the total length of an SVG element using React

Looking to animate an SVG path using React (similar to how it's done in traditional JavaScript: https://css-tricks.com/svg-line-animation-works/), but struggling when the path is created using JSX. How can I find the total length of the path in this s ...

Rendering Error - Animating text using React and Material-UI

Looking for a way to create a scrolling effect line by line? I have a component with name, pronouns, and some humble sub-text that should scroll one item at a time. To handle the scrolling feature, I've set up a separate component called TitleScroll. ...

Creating a dynamic design with a responsive background image and three columns of engaging content placed on top using Bootstrap

I'm struggling to translate a design mockup into Bootstrap 3.3.6 Here is an image showcasing the concept I am aiming for: https://i.sstatic.net/1jZmh.png The blue background represents an image, with grey text boxes overlaid on top (one of which in ...

How can you emphasize the most recent entry in a Datatable?

When dynamically adding rows to my datatable using ajax, I need to apply a specific CSS style to the last row. However, the challenge is that this last row may be on a different page due to datatable pagination. Here's what I attempted: table.row().i ...

Accessing the current instance in Vue when triggered by a checkbox event

Recently, I tested out a to-do-list application built in Vue that has a checkbox feature to mark completed items. I'm looking for a way to access the current instance from the checkbox event. Here's what I've accomplished so far: myObject ...

Arrangement of Div Box

Here is the HTML code that I am currently working with: <div class="item"> <div class="pageheader"> Header </div> <div class="info"> Created on... </div> <div class="image"> I ...

the integration of shapes in three.js is malfunctioning

There has been a dynamic change in the path. The previous render function was as follows (where LENGTH, getPosition(), RADIUS, MATERIAL, and SCENE have already been set) var prevPosition = getPosition(); for(var i =0; i < LENGTH; i++) { drawPath(g ...