Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • jQuery
  • AngularJS
  • ReactJS
  • Next.js
  • React Native
  • NodeJS
  • Express.js
  • MongoDB
  • MERN Stack
  • PHP
  • WordPress
  • Bootstrap
  • Tailwind
  • CSS Frameworks
  • JS Frameworks
  • Web Development
Open In App
Next Article:
Web API UI Events
Next article icon

Web API Pointer Events

Last Updated : 24 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

Web API Pointer events are DOM events that are designed to create a single DOM event model to handle pointing input devices such as a pen, mouse, or touch screen. These are fired as a pointing device. It helps different devices work together smoothly, making sure your experience on websites is always smooth and responsive.

Table of Content

  • Pointer Events Guides
  • Pointer Events Terms
  • PointerEvent Interface
  • Pointer Events Properties
  • Pointer Events Methods
  • Pointer Events

We will explore the above-mentioned topics with the help of suitable examples.

Pointer Events Guides

Terminologies

Descriptions

Using Pointer Events

Using pointer-events and HTML '<canvas>', create a multi-touch drawing app that accepts input from various devices (mouse, pen, fingertip) with the same code.

Note: Requires a browser supporting pointer events.

multi-touch InteractionWeb API pointers enable multi-touch interaction, supporting pens, touch screens, and mice. It allows simultaneous input from multiple pointers, enhancing user experience with additional complexity in interaction handling.
Pinch zoom interactionEnhance the user experience by implementing pinch/zoom gestures in your application. Using pointer events, detect when two pointers move closer or farther apart, enabling intuitive multi-touch interactions.

Pointer Events Terms

The following terms can used with Pointer Events, which are described below:

Events

Descriptions

Active Buttons StateThis term denotes the state when a pointer records a non-zero value for the button's property.
Active PointerAny input device capable of generating events falls under the category of an active pointer. A pointer remains active if it can produce additional events, such as a pen in a down state that can generate events upon being lifted or moved.
DigitizerA digitizer is a sensing device with a surface capable of detecting contact.
Hit TestThe hit test is the browser's process to determine the target element for a given pointer event, considering the pointer's location and the visual layout of elements within a document on the screen.
PointerA pointer is a hardware-agnostic representation of input devices, capable of targeting specific coordinates on a screen. Examples include mice, pens/styluses, and touch contacts.

PointerEvent Interface

It represents a pointer event, including properties like pointerId, pointerType, and isPrimary.

Pointer Events Properties

Navigator.maxTouchPoints

It is a property that informs web developers about the maximum number of simultaneous touch points supported on a user's device. This data helps us to optimize touch-based interactions in their applications, ensuring a seamless and responsive user experience.

Pointer Events Methods

Methods

Description

setPointerCapture( )It is a function that captures a pointer, directing subsequent events to a specified element.
releasePointerCapture( )It frees a captured pointer, allowing it to interact with other elements. These methods offer control over pointer interactions, enhancing the flexibility of web applications.

Pointer Events

Events in the Web API Pointer Events are notifications triggered by pointer-related interactions, such as clicks, taps, and movement.

Web API Events

Description

pointerdownIt is fired when a pointer becomes active.
pointerupFired when a pointer ceases to be active.
pointermoveFired when a pointer is moved or when it changes its coordinates.
pointercancelFired when the input is disrupted.
pointeroverFired when a pointer is moved into an element's hit test boundaries. This event is triggered when the pointer enters the area of an element.
pointerenterFired when a pointer is moved into the hit test boundaries of an element or one of its descendants. This includes cases where a pointerdown event occurs from a device that does not support hover.
pointeroutFired when a pointer is moved out of the hit test boundaries of an element. It can also be triggered after firing the pointerup event for a device that does not support hover or after firing the pointercancel event.
pointerleaveFired when a pointer is moved out of the hit test boundaries of an element. For pen devices, this event is fired when the stylus leaves the hover range detectable by the digitizer.
gotpointercaptureFired when an element receives pointer capture. This event is useful for indicating that a specific element has successfully captured a pointer.
lostpointercaptureFired after pointer capture is released for a pointer. This event occurs when an element that previously captured a pointer releases its capture.

Example 1: In this example, we will see how to implement the above approach in JavaScript.

HTML
<!DOCTYPE html> <html lang="en">  <head>     <meta charset="UTF-8">     <meta name="viewport"            content="width=device-width,                     initial-scale=1.0">     <title>Web API Pointer Events</title> </head>  <body>     <h1>GeeksforGeeks</h1> </body> <script src="script.js"></script>  </html> 
JavaScript
// script.js document.addEventListener('pointerdown', (event) => {     console.log(`Pointer down at (${event.clientX}, ${event.clientY})`); });  document.addEventListener('pointerup', (event) => {     console.log(`Pointer up at (${event.clientX}, ${event.clientY})`); });  document.addEventListener('pointermove', (event) => {     console.log(`Pointer moved to (${event.clientX}, ${event.clientY})`); }); 

Output:

aw

Example 2: The following example demonstrates how to handle pointer events and capture/release pointers on a specific element.

HTML
<!DOCTYPE html> <html lang="en">  <head>     <meta charset="UTF-8">     <meta name="viewport"            content="width=device-width,                    initial-scale=1.0">     <title>Web API Pointer Events Example</title>     <style>         #target {             width: 200px;             height: 200px;             background-color: lightblue;             margin: 50px;             text-align: center;             line-height: 200px;             cursor: pointer;         }     </style> </head>  <body>     <div id="target">Click and Drag</div>      <script>         document.             addEventListener('DOMContentLoaded', () => {                 const targetElement =                     document.getElementById('target');                  targetElement.                     addEventListener('pointerdown', (event) => {                                            // Capture the pointer for this element                         targetElement.                             setPointerCapture(event.pointerId);                          // Change the background color on pointer down                         targetElement.                             style.backgroundColor = 'lightcoral';                          console.log(`Pointer captured for element`);                     });                  targetElement.addEventListener('pointerup', (event) => {                                        // Release the captured pointer                     targetElement.                         releasePointerCapture(event.pointerId);                      // Change the background color back on pointer up                     targetElement.                         style.backgroundColor = 'lightblue';                      console.log(`Pointer released from element`);                 });                  targetElement.addEventListener('pointermove', (event) => {                                        // Move the element with the pointer                     targetElement.style.left =                         (event.clientX - 100) + 'px';                     targetElement.style.top =                         (event.clientY - 100) + 'px';                 });             });     </script> </body>  </html> 

Output:

ezgifcom-crop-(1)

Browser Support

  • Google Chrome 55
  • Edge 12
  • Firefox 59
  • Apple Safari 42
  • Opera 13

Next Article
Web API UI Events

P

pawan_malik
Improve
Article Tags :
  • Web Technologies
  • Geeks Premier League
  • Web-API
  • Geeks Premier League 2023

Similar Reads

  • Web API UI Events
    Web API UI Events is a system that is used to handle the event that occurs in the UI layer. This UI event can be a mouse event or keyboard event. This API provides some use full modules to handle events. These events helped us to design the dynamic UI for the web pages and web applications. There ar
    4 min read
  • SVG pointer-events Attribute
    The pointer-events attribute allows us to define whether or when an element may be the target of a mouse event. It is applied on the following elements: <a>, <circle>, <clipPath>, <defs>, <ellipse>, <foreignObject>, <g>, <image>, <line>, <mark
    3 min read
  • Tailwind CSS Pointer Events
    This class accepts lots of value in tailwind CSS in which all the properties are covered in class form. This class is used to specify whether elements show to pointer events or not show on the pointer. In CSS, we do that by using the CSS pointer-events property. Pointer Events Classes: pointer-event
    1 min read
  • Web API Device Orientation Events
    Web API Device Orientation Events provide a mechanism to access a device's orientation data, including alpha, beta, and gamma angles, representing yaw, pitch, and roll. These events are triggered when there is a change in the device's orientation. Developers can utilize this information to create im
    3 min read
  • React onPointerUp Event
    React onPointerUp event fires when the mouse button is clicked and released and it detects the right, left, or middle click of the mouse. Similar to other events, we have to provide a function that will execute their process. Syntax:onPointerUp={function}Parameter : function that will call once any
    2 min read
  • React onPointerMove Event
    The onPointerMove event in React fires whenever the cursor moves inside the tag or element where the event has been applied. Similar to other events, the onPointerMove takes a function which defines the process/task which has to be applied. Syntax:onPointerMove={function}Parameter : function: The fu
    2 min read
  • React onPointerDown Event
    The onPointerDown event in React fires whenever the pointer (mouse) is down i.e. clicked over the tag or element over which the event has been applied. Similar to other events, we have to provide a function which executes the task or process when the event occurs. Syntax:onPointerMove={function}Para
    2 min read
  • Web API Vibration
    Web API Vibration enables web developers to manage device vibrations and enrich user interactions. The Web API Vibration is a part of the Web APIs that enable web developers to interact with the hardware features of a user's device. Specifically, it allows developers to control the vibration motor o
    4 min read
  • React onPointerCancel Event
    React onPointerCancel fires when a pointer event cancels, like when someone is zoomed into an image and the user suddenly leaves it, which is a part of the onPointerCancel event. Syntax:onPointerCancel={function}Parameter : function that will call once any pointer event cancels.Return type: event: I
    2 min read
  • Spring - Application Events
    Spring is a popular Java-based framework that helps developers create enterprise applications quickly and efficiently. One of the most powerful features of the Spring framework is its Application Events feature, which allows developers to create custom event-driven applications. What are Spring Appl
    5 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences