简体   繁体   English

鼠标相对于单击元素的位置

[英]Relative mouse position to clicked element

I have a short question. 我有一个简短的问题。

I'm using the FooBox plugin on my Wordpress site, accompanied by FooGallery. 我在Wordpress网站上使用了FooBox插件,并伴随着FooGallery。 Now I want to add a little tweak with javascript. 现在,我想对javascript进行一些调整。

When I click on an image, the FooBox will show up, with arrows to the left and right. 当我单击图像时,将显示FooBox,并带有左右箭头。 I want to add the same functionality to the image itself, so when you click the left side of the image it will go back in gallery, and if you click the right, it will go to the next image. 我想为图像本身添加相同的功能,因此,当您单击图像的左侧时,它将返回图库,而如果单击右侧,则将转到下一个图像。

I've already know the answer in jQuery, but now i need a pure JS solution. 我已经知道jQuery的答案,但是现在我需要一个纯JS解决方案。 Thanks in advice! 感谢您的建议!

When you have the element using 当您使用元素

var elem = document.getElementById('yourId')

or 要么

var elem = document.getElementsByClassName('yourClass')[0]

or whatever 管他呢

you may then add a handler to the onclick event 然后可以将处理程序添加到onclick事件

eg 例如

elem.onclick = function(e){
  console.log(e)
}

log: 日志:

click clientX=480, clientY=63 点击clientX = 480,clientY = 63

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM