此代碼在 chrome 中運行良好
$("#el").hover(function () {
let position = $(this).offset();
$('#popover').css(position);
});
但是 offset() 總是在 safari 中回傳這個:
{top: 0, left: 0}
#el 是一個 svg 圈
<circle id="el" cx="500" cy="153" r="50"></circle>
這是jQuery的問題嗎?
作業示例:
在 Safari 中:
uj5u.com熱心網友回復:
以下代碼兼容所有瀏覽器:
$("#el").hover(function () {
const circle = document.getElementById('el').getBoundingClientRect();
const position = { left: circle.left, top: circle.top };
$('#popover').css(position);
console.log(position)
});
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/374150.html
上一篇:調整SVG大小以填充div