The EventListener functions properly only when the browser window is not in focus

In my Angular application, I am using Two.js to draw an SVG image. After drawing the SVG with some elements in Two.js, I add event listeners to its elements like so:

this.courtRenderer.update(); // once this command is executed, Two.js will draw the SVG

for (const trajectory of this.trajectories) {
  trajectory.renderedLine._renderer.elem.addEventListener('mouseenter', (event) => {
    this.onRenderedLineMouseEnter(event, this.trajectories.filter((selectedTrajectory) =>
    selectedTrajectory.renderedLine.id === trajectory.renderedLine.id));
  }, false);
  trajectory.renderedLine._renderer.elem.addEventListener('mouseleave', () => {
    this.onRenderedLineMouseLeave(this.trajectories.filter((selectedTrajectory) =>
    selectedTrajectory.renderedLine.id === trajectory.renderedLine.id));
  }, false);
}

After setting up the event listeners, there is a handler that changes the line width and color, as well as triggers a service to open a popup at the position of the mouse.

private onRenderedLineMouseEnter(event, trajectories){
    let renderedLine;
    for (const trajectory of trajectories){
      renderedLine = trajectory.renderedLine;
      renderedLine.linewidth = renderedLine.linewidth * this.appConfig.courtRenderer.highlightedTrajectoryWeight;
      renderedLine.stroke = this.appConfig.courtRenderer.colors.highlightedTrajectory;
    }
      this.courtRenderer.update();
      const popupPosition = new PopupPosition(renderedLine.id, event.layerX, event.layerY);
      this.virtualCourtService.selectShot(popupPosition);
    }

However, the functionality does not work properly until I open the console in the browser by pressing F12. It's strange because everything works fine after that. Any idea why it doesn't work initially?

Edit: I noticed that when I set a breakpoint in the "onRenderedLineMouseEnter" method and trigger the mouseenter event on the line, the code works without relying on the Inspector tool.

I even added some console.log statements to the method, and whether or not the Inspector is open, the code executes. But only with the Inspector (or a breakpoint), the UI changes are reflected visually.

Answer №1

Something interesting I have noticed - handlers function properly when the browser window is inactive, but when the window is clicked on and becomes active, they stop working. This led me to think about using the inspector tool - as the inspector became the active window, causing the browser content to become inactive. https://i.sstatic.net/Zg8cJ.png

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

Determine the Orientation of an Accelerometer using a JavaScript function in Node-RED

Is there a way to determine the orientation of a sensor using a JavaScript function? I came across an example on 3D Accelerometer calculate the orientation, but I'm struggling to understand how to utilize the values of msg.payload.xAxis/yAxis/zAxis fo ...

Avoid an excessive number of XHR/AJAX requests when using the Facebook embedded iframe

I am facing an issue with a Bootstrap Carousel that contains multiple social embeds from Facebook, all of which have videos. The problem is evident on this simple jsfiddle due to the Facebook embed. If you visit this page: https://jsfiddle.net/1L95vqn4/, ...

"What's the best way to make sure a checkbox stays checked and its content remains visible after a

After updating my HTML content, it now consists of a hidden table inside a div with the class "myClass": <div class="myClass" style="display:none"> <table class="table table-hover"> ..... </table> </div> The table remains hidden u ...

Node.js application experiencing bug with End of Line (EOL) not displaying correctly

I've encountered an issue with my node.js application that involves writing the following code: word_meaning = 'line 1' + os.EOL +'line 2'; When attempting to render this in an HTML file using the following code: <p> <% ...

Using AngularJS to hide elements within a nested dictionary structure

My dictionary structure is as follows: var data = { a: [1, 2, 3, 4, 5], b: [ [1, 2], [3, 4], [5, 6] ] }; Currently, I am using ng-hide to hide an element if the value 2 exists in data->a. Here's how it's implemented: <i ...

What is the process for activating a button after a checkbox has been selected? Additionally, how can a value be dynamically transferred from a checkbox to the rezBlock_1 block?

What could be the reason for my code not functioning properly? How can I enable a button once a checkbox is selected? Also, is there a way to dynamically move text from a checkbox to the rezBlock_1 block? CODPEN https://codepen.io/RJDio/pen/RwPgaaZ doc ...

Styling with CSS to create a visual countdown display

I'm trying to replicate the format shown in the image below. https://i.sstatic.net/lnW2C.png Currently, this is the code I have: https://codepen.io/Brite1/pen/wvPrggj (it seems like I just need to adjust spacing and center all numbers/text). I'm ...

Adjusting a parameter according to the width of the browser window?

Using Masonry, I have implemented code that adjusts the columnWidth to 320 when the screen or browser window width is less than 1035px. When the width exceeds 1035px, the columnWidth should be 240. However, the current code keeps the columnWidth at 320 re ...

Search through an array, identify duplicates, and transfer them into a separate array

I am working with an array of objects containing dates and I am looking to extract objects with the same date values into a new array. Below is the code snippet. var posts = [ { "userid": 1, "rating": 4, "mood": "happy", "date": "2 ...

Steps for removing an element from an array after unchecking a checkbox:

My issue involves handling multiple locations - when a particular location is checked, it gets added to an array. However, I am unable to remove it from the array when the checkbox is unchecked. handleChange(e){ if(e.target.checked){ let selec ...

Strategies for managing asynchronous forEach loops, inserting outcomes into a database, and displaying the finalized dataset

I want to achieve the following steps: Call an API resource Receive an array of records - [arr] Iterate over [arr] and execute a function which involves making another async call to an API for each item Create an object for each iteration that includes el ...

What is the recommended way to configure the build.gradle file for the app build process?

I am currently working on building the app using the command provided below. /android gradlew assembleRelease My main query at this point is whether it is necessary to eliminate the debug of signingConfigs and debug of buildTypes when transitioning into r ...

Obtain the node identifier within the Angular UI Tree component [angular-ui-tree]

Utilizing Angular UI tree to create a relationship between items and categories has been successful in the default setup. However, a new requirement has emerged to incorporate node/section numbering within the tree for managing hierarchy. I attempted to i ...

I need my styled component to make sure my inner div spans the entire width of its parent div

I'm having an issue with my NavDiv styled component not taking up the full height of my Wrapper styled component. I've tried setting the height using different units like percentage, em, rem, but it doesn't seem to work. It only works when u ...

Removing a post in Meteor-React using a submission modal is not possible as the post is not defined

After creating an additional submit modal for user confirmation when deleting a post from the collection, I'm facing difficulty in targeting the post. I also have a productivity query - should I include the DeletePost component in each post component ...

Using the Jquery accordion function within google maps is limited to running only one time

After successfully creating a google maps page with markers generated from XML, I encountered an issue. The plan was to display event information in a div when a marker is clicked, along with attaching an accordion to the events data. Although the first cl ...

Incorporate a fresh value into an array within MongoDB

I'm attempting to add a new value to an array inside an object using the following method: await database.models.updateMany( { <queue> }, { $push: { object: { array: 'Hello, World!' }}}); However, instead of adding a new value, it del ...

ngTagsInput - Enable the onTagAdding feature

I've been attempting to establish a default function for the onTagAdding callback using the tagsInputConfig provider, but without any success. tagsInputConfig.setDefaults('tagsInput', { placeholder: 'Search', maxTags: 10, ...

Strikeout list on click of a mouse

Is there a way to apply strikethrough formatting to text with just a mouse click? The CSS for lists is beyond the form field margin. I've tried multiple methods without success. No matter how many times I change the code, I can't seem to get it r ...

Using the inline calendar feature of Bootstrap 3 Datepicker to easily select and capture dates

I've been struggling to extract the selected date from my bootstrap 3 datepicker, and despite attempting to follow the documentation, I still can't grasp it. Here's what I tried: <div id="datetimepicker"> <i ...