Home > Web Front-end > JS Tutorial > body text

How Can I Capture Mouse Wheel Events in jQuery?

Patricia Arquette
Release: 2024-10-26 00:54:28
Original
318 people have browsed it

How Can I Capture Mouse Wheel Events in jQuery?

Capturing Mouse Wheel Events in jQuery

jQuery offers an effective method to capture specific mouse wheel events, distinct from scroll events. This article will guide you through the process of achieving this functionality.

The mouse wheel event allows you to detect precise wheel movements without relying on scrolling actions. To initiate event handling, you can utilize the bind() function as follows:

<code class="javascript">$(document).ready(function(){
    $('#foo').bind('mousewheel', function(e){
        if(e.originalEvent.wheelDelta /120 > 0) {
            console.log('scrolling up !');
        }
        else{
            console.log('scrolling down !');
        }
    });
});</code>
Copy after login

In this example, the mousewheel event listener is attached to an element with the ID foo. The e.originalEvent.wheelDelta property designates the direction of the wheel movement, where positive values represent upward scrolling and negative values denote downward scrolling.

This approach provides a direct and efficient way to monitor mouse wheel interactions, enabling you to respond to precise user inputs in real-time.

The above is the detailed content of How Can I Capture Mouse Wheel Events in jQuery?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!