如何在鼠标单击位置打开弹出窗口 [英] How to open a popover on the mouse click location
本文介绍了如何在鼠标单击位置打开弹出窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经在我的HTML页面上加载了一个图像,我想在Twitter Bootstrap的鼠标点击位置打开一个popover。
到目前为止我所做的是打开图像侧面的弹出窗口。但我真正想要做的就是在我点击图片的地方打开popover。
I have loaded an image on my HTML page and I'd like to open a popover from Twitter Bootstrap right over the mouse click position. What I have done so far is to open the popover on the side of the image. But what I really want to do is to open the popover wherever I've clicked on the image.
我怎样才能做到这一点?
How can I achieve this?
推荐答案
你需要得到鼠标坐标并使您的脚本使用它们来定位弹出窗口。如果您正在使用jQuery,这可能有所帮助:
You need to get the mouse coordinates and make your script use them to position the popover on click. If you're using jQuery this might help:
$('#yourimage').click(function(){
$('#popover').css('left', pageX-(popover width)+'px');
$('#popover').css('top', pageY-(popover height)+'px');
})
---编辑---
Here's a demo of what you're after.
这篇关于如何在鼠标单击位置打开弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文