Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

access mouse position javascript

(function() {
    document.onmousemove = handleMouseMove;
    function handleMouseMove(event) {
        var eventDoc, doc, body;

        event = event || window.event; // IE-ism

        // If pageX/Y aren't available and clientX/Y are,
        // calculate pageX/Y - logic taken from jQuery.
        // (This is to support old IE)
        if (event.pageX == null && event.clientX != null) {
            eventDoc = (event.target && event.target.ownerDocument) || document;
            doc = eventDoc.documentElement;
            body = eventDoc.body;

            event.pageX = event.clientX +
              (doc && doc.scrollLeft || body && body.scrollLeft || 0) -
              (doc && doc.clientLeft || body && body.clientLeft || 0);
            event.pageY = event.clientY +
              (doc && doc.scrollTop  || body && body.scrollTop  || 0) -
              (doc && doc.clientTop  || body && body.clientTop  || 0 );
        }

        // Use event.pageX / event.pageY here
    }
})();
Comment

access mouse position javascript


(function() {
    document.onmousemove = handleMouseMove;
    function handleMouseMove(event) {
        var eventDoc, doc, body;

        event = event || window.event; // IE-ism

        // If pageX/Y aren't available and clientX/Y are,
        // calculate pageX/Y - logic taken from jQuery.
        // (This is to support old IE)
        if (event.pageX == null && event.clientX != null) {
            eventDoc = (event.target && event.target.ownerDocument) || document;
            doc = eventDoc.documentElement;
            body = eventDoc.body;

            event.pageX = event.clientX +
              (doc && doc.scrollLeft || body && body.scrollLeft || 0) -
              (doc && doc.clientLeft || body && body.clientLeft || 0);
            event.pageY = event.clientY +
              (doc && doc.scrollTop  || body && body.scrollTop  || 0) -
              (doc && doc.clientTop  || body && body.clientTop  || 0 );
        }

        // Use event.pageX / event.pageY here
    }
})();

Comment

PREVIOUS NEXT
Code Example
Javascript :: how to copy text from input through button click js 
Javascript :: 1 dollar in rupees 
Javascript :: bootstrap searchable pagination table example jquery 
Javascript :: react radio button checked not working 
Javascript :: react hide element 
Javascript :: lastindexof() javascript 
Javascript :: javaScript setMinutes() Method 
Javascript :: axios response.json 
Javascript :: append http to url 
Javascript :: react native showing double header stack and drawer menu 
Javascript :: react native webview postmessage example 
Javascript :: reverse js 
Javascript :: get nearest location based on latitude and longitude javascript 
Javascript :: js read external json file js 
Javascript :: json api 
Javascript :: local vs global variables 
Javascript :: change cwd node 
Javascript :: array.slice 
Javascript :: vue js datetime convert 
Javascript :: all redux reuired packages 
Javascript :: ssr full form in nextjs 
Javascript :: react context api with hooks 
Javascript :: react native keyboard push view up 
Javascript :: preventdefault javascript 
Javascript :: angular material dropdown menu 
Javascript :: method chaining in javascript 
Javascript :: js var vs let 
Javascript :: javascript check if element has specific child 
Javascript :: Not Found The requested URL was not found on this server angular routing when going back to site from ecternal source 
Javascript :: js clearect 
ADD CONTENT
Topic
Content
Source link
Name
6+6 =