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:
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
Post a Comment