html - compute mouse position within video with object-fit:contain -


i trying convert mouse event pixel coordinates within video. pixel coordinates, mean coordinates relative original video resolution.

my video element has object-fit: contain, means top left corner of video not located @ position (0,0), picture shows:

enter image description here

if click on top-left corner of white section in video want (0,0), in order need discover offset of video content (white area) relative video element (black border).

how can recover offset?

i aware of width, height, videowidth, , videoheight, these let me account scaling, not offset.

the offset can deduced. think kind of code should trick:

if(videoheight/height > videowidth/width){     scale   = videoheight/height;     offsetx = (videowidth - width*scale)/2;     offsety = 0; } else{     scale   = videowidth/width;     offsety = (videoheight - height*scale)/2;     offsetx = 0; } 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -