我的目標是獲取top
和left
的位置cursor
當單擊一個button
並將其分配給popover
。這樣做的目的是讓popover
恰好處於被點擊的位置。請參考https://jsfiddle.net/VUZhL/2684/動態獲取鼠標點擊事件頂部和左側
<a id="example" class="btn btn-primary" rel="popover" (click)="showCords($event)"
data-content="This is the body of Popover"
data-original-title="Creativity Tuts">pop
</a>
這裏onclick
事件我打電話的function
得到clientX
和clientY
。
但似乎沒有工作。我是bootstrap
的新手,剛開始學習,甚至不知道這是否有效。最壞的部分是我應該只使用javascript
不是JQUERY
。即使JSFiddle只是一個基本的。
任何幫助表示讚賞。
感謝提前:)
更新:
function showCords(event) {
var x = event.clientX;
var y = event.clientY;
var coords = "X coords: " + x + ", Y coords: " + y;
document.getElementById("example").setAttribute("data-content", coords);
document.getElementById("example").style.left="x";
document.getElementById("example").style.top="y";
$('#example').popover();
}
有人能告訴我什麼是確切的錯誤我在做什麼。我正在嘗試這樣做http://codepen.io/rm89/pen/aNOmzQ這裏我的popover必須在我點擊buuton的位置。
更新2::
How to open a popover on the mouse click location。上述鏈接中的答案是實際需要,但不幸的是它在JQUERY中。有人可以幫助我在改造回答JAVASCRIPT
感謝RESP [ONSE。但popover沒有被觸發? – Karthi