Search
 
SCRIPT & CODE EXAMPLE
 

CSS

get clicked position javascript image

 // https://stackoverflow.com/questions/34867066/javascript-mouse-click-coordinates-for-image
  document.getElementById(imageid).addEventListener('click', function (event) {
    // https://stackoverflow.com/a/288731/1497139
    bounds=this.getBoundingClientRect();
    var left=bounds.left;
    var top=bounds.top;
    var x = event.pageX - left;
    var y = event.pageY - top;
    var cw=this.clientWidth
    var ch=this.clientHeight
    var iw=this.naturalWidth
    var ih=this.naturalHeight
    var px=x/cw*iw
    var py=y/ch*ih
    alert("click on "+this.tagName+" at pixel ("+px+","+py+") mouse pos ("+x+"," + y+ ") relative to boundingClientRect at ("+left+","+top+") client image size: "+cw+" x "+ch+" natural image size: "+iw+" x "+ih );
  });
Comment

PREVIOUS NEXT
Code Example
Css :: change svg color in pseudo element 
Css :: -webki slider runnable track 
Css :: css code for flash messages flask 
Css :: const Schema 
Css :: Getting strated with boostrap css for html and Reacr framework 
Css :: position absolute prevent overflow 
Css :: disabled attribute on button still showing click animation safari macos 
Css :: jitsi meet index.html add css version 
Css :: purpose 
Css :: padding 2 values how would be they applied 
Css :: chrome remove black inline from click button 
Css :: #shadow-root (open) css 
Css :: nokogiri xml diff 
Css :: how to use css print page break with float 
Css :: clamp(css) 
Css :: look and feel 
Css :: how to use class form scss reactjs 
Css :: outline letters in sass 
Css :: css image grow on hover without text content 
Css :: button size css 
Css :: what is integrity cdn 
Css :: elemento SPAN 
Css :: browser renders before styles are applied 
Css :: media query in css 
Css :: css float and clear 
Css :: materialize table padding css 
Typescript :: remove dots from li 
Typescript :: ionic 3 alert backdrop dismiss 
Typescript :: room dependency android 
Typescript :: list open ports firewalld 
ADD CONTENT
Topic
Content
Source link
Name
8+2 =