The scroll wheel function is having issues in Internet Explorer

My application requires tracking mouse wheel movement, but the functions I've written aren't working properly in Internet Explorer. They work fine in all other browsers except IE. Any suggestions on what might be causing this issue?

JS...

var request = true;
var onMouseWheelSpin = function(event) {
    if(request === true){ 
        request = false;
        var nDelta = 0;
        if (!event) { event = window.event; }
        // Cross-browser handling of event data to determine delta (+1 or -1)
        if ( event.wheelDelta ) { // For IE and Opera
            nDelta= event.wheelDelta;
            if ( window.opera ) {  // Opera has the values reversed
                nDelta= -nDelta;
            }
        }
        else if (event.detail) { // For Mozilla FireFox
            nDelta= -event.detail;
        }
        if (nDelta > 0) {
            zoomFun( 1, event );
        }
        if (nDelta < 0) {
            zoomFun( -1, event );
        }
        if ( event.preventDefault ) {  // For Mozilla FireFox
            event.preventDefault();
        }
        event.returnValue = false;  // Cancel default action
    }
}

var zoomFun = function(delta,e) {
    if(delta > 0){ // Zoom in
        alert("In");
    }else{ // Zoom out
        alert("Out");
    }
    request = true;
}

var setupMouseWheel = function(){
    // For mouse scrolling in Firefox
    var elem = document.getElementById("zoom");
    if (elem.addEventListener) {    // All browsers except IE before version 9
        // For Internet Explorer, Opera, Google Chrome, and Safari
        elem.addEventListener ("mousewheel", onMouseWheelSpin, false);
        // For Firefox
        elem.addEventListener ("DOMMouseScroll", onMouseWheelSpin, false);
    }else{
        if (elem.attachEvent) { // For IE Before version 9
            elem.attachEvent ("onmousewheel", onMouseWheelSpin);
        }
    }   
}

I am calling the setupMouseWheel function onload in the body as:

<body onload="setupMouseWheel();">

Thank you for your assistance!

Answer №1

If you want to detect mouse wheel movement, it's recommended to pay attention to DOMMouseScroll, mousewheel, and wheel. The last one specifically caters to IE, so make sure not to overlook it.

On another note, jQuery offers a convenient method for attaching multiple event handlers at once:

 $(elem).on("DOMMouseScroll mousewheel wheel", handleMouseWheel);

Update: I noticed that even though you mentioned jQuery, you aren't utilizing it in your code. However, if you prefer the non-jQuery route, simply continue with the same approach but remember to include a wheel event listener alongside the others.

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

Extracting information from a checkbox list displayed within an HTML table

I have a table with multiple rows and two columns in each row. The first column contains text, and the second column consists of checkboxes. While I was able to retrieve the values from the first column, I am struggling to fetch the values of the selected ...

I've noticed that the NextJs router appears to be significantly slower in comparison to React

I currently have a website that is built in both React Js and Next Js. The issue I am currently encountering is that the router in NextJs is noticeably slower compared to react-router-dom. It takes almost 2-3 seconds to change the route. To experience th ...

Navigating through ajax requests on a Leaflet map

Currently, I have a leaflet map set up with the leaflet-panel-layers plugin to create a visually appealing layer control. To create my layers and overlays, I have two functions in place. The issue arises when trying to access external geoJSON files, as lea ...

Ext JS - A grid cell containing varying values, accompanied by a selection of combo boxes

I'm currently implementing the Ext JS Grid component and have a list of fields with their respective data types: ID (int) Name (string) Foods (List<string>) Each user can have multiple foods, selected from a Food DataStore. Displaying this in ...

Leveraging jQuery for handling button functionality and making asynchronous requests

I am relatively new to working with jQuery, and while there are plenty of resources available on how to bind buttons, I find that my current setup is a bit more complex than what's typically covered. My situation involves: -Using Django to populate ...

Troubleshooting issues with multiple $scope.$watch functions in AngularJS

I'm having an issue where only the first $watch function is firing in the same controller. Both inputs have ng-model assigned to them. Can someone help me understand why this is happening? (appreciate any help) $scope.$watch('search', funct ...

Altering the value of a global variable through a local function in JavaScript

I have developed a straightforward piece of Java script code. I'm looking to update the value of a global variable using a local function. Whenever I trigger the value1() function, I want the output to display as "2". Is there a way I can achieve this ...

Fade in and out a Div with a distinct class and ID

I'm currently experiencing a minor issue with some jQuery code. Below are some divs: <div class="add" id="1">Follow</div> <div class="added" id="1">Following</div> <div class="add" id="2">Follow</div> <div clas ...

How can I utilize Axios in Vue.js to access a local JSON file?

I'm trying to figure out how to read a local JSON file using Axios. The data.json file is located in public/info/data.json. However, every time I attempt to make a get request, I receive a 404 error message. Here is the content of data.json: [ {" ...

Pass a PHP string to a JavaScript function using AJAX

Recently, I encountered an issue with my database storing email content. To retrieve this content, I made an ajax request and wanted to pass the data to a function that would display a popup with the email content. However, the email content contains HTML ...

Error: The object "request" has not been defined. This issue occurs when trying to execute an Action

$dd = "<a href='javascript:void(0);' id='requestsend$send_id' onClick='request($send_id,request_send);' class='post-add-icon inline-items'><button type='button' style='background: #ccc;' ...

Unable to retrieve PHP data using AJAX

Index.html → <form> <div class="form-group"> <!-- <input type="text" id="name" class="form-control" placeholder="Enter Name"> --> </div> <div ...

Chrome autocomplete behaves as if the input fields are disabled and cannot be clicked on

I am experiencing an unusual issue with autofill in Chrome. After logging in and then logging out of the app, the input fields (email, password) are auto-filled but appear to be frozen and unclickable. This problem does not occur every time; it only happe ...

Is there a bug in NodeJS that causes an error when a return statement is used with a line feed before the string to be returned?

I am attempting to call a function from a module in order to generate an HTML string. When the function is written with a line feed (LF) between the return statement and the string declaration as shown below, the return value becomes "undefined"... export ...

How do I fix TypeError: req.flash is not a valid function?

While working with user registration on a website, validation is implemented using mongoose models and an attempt is made to use Flash to display error messages in the form. However, in my Node.js app, an error is occurring: TypeError: req.flash is not ...

What is the method for linking events across multiple objects?

When a user clicks on the confirmation button in a Twitter Bootstrap modal window, I trigger a deletion action on the page. The modal contains two buttons - one for canceling the action and another for confirming it. Once the user confirms the delete act ...

Using Javascript to trigger a setTimeout function after the user's mouse leaves

There is a div that pops up when the user's mouse exits the webpage, containing a survey pertaining to my website. I want to avoid prompting users to take the survey if they move their cursor out of the page within the first few minutes of browsing. ...

Converting a jQuery function into AngularJS: A step-by-step guide

I'm completely new to AngularJs and I recently created a slider function using jQuery. Now, my goal is to convert this function into Angular. Below is the code snippet that I have: <div class="slide-container"> <div class="slide-s ...

A guide to JavaScript: Fetching and Parsing JSON Data from an API

Hey there! I've been working on using this code snippet in my defult.js file to call an API, but I'm having trouble figuring out how to read the output. It always seems to end up in the last else part. function fetchDataDist(APPID, flag, call ...

Using JavaScript or JQuery, move an image from one location to another by removing it and adding

Firstly, feel free to check out the JSFiddle example My task involves moving an image with the class "Full" after a div with the class "group-of-buttons" using JavaScript. Here is the snippet of HTML code: <img src="http://i.telegraph.co.uk/multimedia ...