Prevent scrolling using mousewheel click (auxclick event)

Currently working with Angular 9 and encountering an issue with the (auxClick) event triggering on a mousewheel click. The problem arises when attempting to use this event while there is a scroll present on the page, as it does not trigger correctly due to the automatic scrolling behavior associated with mousewheel clicks.

I am specifically looking to disable this functionality, which can be seen in action here: https://i.sstatic.net/c5hB7.png

Has anyone found a way to disable this behavior using JavaScript or TypeScript within an Angular environment?

Thank you for any assistance provided.

(Please note that utilizing preventDefault() has not proven effective, as the event itself fails to trigger, thus bypassing the need for any callback functions.)

Answer №1

If you want to stop the scroll effect on your element, there are a couple of ways to do it. You can achieve this using jQuery or Vanilla JS:

Using jQuery:

$('YourElement').on('mousedown', function(e) {
  if (e.which === 2) {
    preventDefault();
    // OR return false;
  }
});

Using Vanilla JS:

 document.getElementsByClassName("YourClassHere")[0].onmousedown = function(e) {
  if (e.which === 2) {
    preventDefault();
    // OR return false;
  }
};

You can also use getElementById for selecting elements by their id or getElementsByTagName for selecting elements by tag name. Just remember to adjust the index if needed when using getElementsByClassName, or remove it when using getElementById.

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 dividing the rows within an array using the match() function?

Within my matrix are arrays of rows. let matrix=[['hello'],['world']]; I am looking to duplicate each row within the matrix. matrix=matrix.map(x=>String(x).repeat(2)).map(x=>x.match(new RegExp??)) The desired outcome should be [ ...

Create an NPM package using the open-api-generator gradle plugin

Has anyone successfully generated an npm package using the open API generator plugin for Gradle? I was able to generate .ts model classes using the typescript-angular generator, but I noticed properties like npmName and npmVersion which made me wonder if ...

Ways to send data to a popup in svelte

Hey there, I could really use some assistance with my Svelte app. I'm trying to implement a modal and pass a parameter to the modal component in order to customize its content. However, when using the open() function of Modal, we only need to provide ...

When it comes to the CSS `:visited` pseudo-class, I have

I'm having trouble changing the color of the anchor tag and blurring the image after visiting the link. Despite my CSS code, only the color is changing and the image remains unchanged. Here's my CSS code: <style> .image123{ paddin ...

What is the best way to create a fresh revision with every build in Vue.js?

Currently, I am utilizing vue cli along with pwa (workbox). Upon building the project, Vue automatically generates a file called: precache-manifest.882c44d211b70f8989278935.js. Within this file, there are entries for revision and url: { "revision": ...

What is the best way to generate conditional test scenarios with Protractor for testing?

Currently, there are certain test cases that I need to run only under specific conditions. it ('user can successfully log in', function() { if(siteAllowsLogin) { ..... } The problem with the above approach is that even when sitesNo ...

Angular routing is showing an undefined ID from the snapshot

When a user attempts to update a student, I pass in the student ID. The update successfully redirects to the updateStudent page and displays the student ID in the browser link. However, within my app component, it shows as undefined. Student View componen ...

Managing Jawbone API OAuth access tokens using node.js (express and passport)

Is there anyone who has successfully completed the Jawbone's OAuth2.0 authentication process for their REST API? I am facing difficulty in understanding how to access and send the authorization_code in order to obtain the access_token as mentioned in ...

What is the process to ensure a React JS click handler updates the DOM upon execution?

I have almost completed a demo app using React JS, where data is displayed in a table. In the status column, hovering over an item triggers a popup div with 3 options to click on. After clicking on an option, I am able to run the click handler, but I' ...

Guidelines on incorporating several JavaScript functions with variables in a single file

Having some trouble figuring out how to incorporate multiple functions with variables in a single JavaScript file. The syntax is throwing me off. I'm attempting to follow an example from randomsnippets.com but would like to expand it to allow for add ...

What is the most effective way to determine which radio button is currently selected in a group with the same name using JQuery?

<form class="responses"> <input type="radio" name="option" value="0">False</input> <input type="radio" name="option" value="1">True</input> </form> Just tested: $('[name="option"]').is(':checked ...

Troubleshooting ES Lint Issue: Passing Parameters to a Vue Method

I'm encountering an ES Lint Parsing Error in my Vue page due to a syntax issue. The problem seems to be arising from a parameter in my method that contains a dot symbol. Error - Syntax Error: Unexpected token (1:1628) <div class="text-sm ...

Angular2: Retrieving the XLS file received from the backend

I am utilizing Laravel 5.1 REST API along with the maatwebsite solution to create an Excel file from the back-end. My main goal is to initiate the download of the file upon button click. Currently, I am making an AJAX request through Angular2's Http s ...

Tips for restricting access to specific routes in VueJS using Store state

Once a user is authorized, their user type is saved to the state. Based on this type, I need to dynamically show or hide specific routes. src/store/index.js: import Vue from "vue"; import Vuex from "vuex"; import getters from "./getters"; import user from ...

for each and every object, execute the asynchronous function

I have a scenario where I need to loop through objects, call an async method ("search") with a callback, and then write the results (resultSet) to a JSON file once all objects are processed. The issue I'm facing is that the writeFile function is execu ...

Whenever I clear the contents of the datatable, I notice that 2 thead elements

I am facing an issue with a table that I populate using jQuery's .append() function and then initialize it as a datatable. Since the data is not fetched via an ajax call, I clear both the tbody and thead using .empty(). However, I encounter a problem ...

Passing a function as a prop within a loop in ReactJs: Here's how to

Looking for assistance on how to send a function in a loop without encountering errors. Is there a way to successfully send a function in a loop and then call it from the function? In CommentListItem.js, I am calling SubCommentListItem. <SubCommentLis ...

Retrieving a variable's value for use in a jQuery UI function

Currently, my project involves using HTML, CSS, JavaScript, and jQuery to develop a UI palette for a Sketchup plug-in. Within this palette, there are multiple instances requiring an input box paired with a slider. To efficiently create these combinations, ...

Webpack is unable to properly parse TypeScript files, resulting in a module parse error that states: "Unexpected token

While working on an old project, I decided to set up Typescript and Webpack. However, I ran into a sudden error: You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js ...

Encountering a syntax error when trying to parse a local storage object?

I've been exploring ways to store random numbers generated by Math.random. I've come up with a solution where I save the numbers in an array, which is then stored in localStorage. My goal is to append each new array of numbers whenever Math.rando ...