使用 jQuery.offset() 查找 SVG 的位置在 safari 中不起作用
Find position of an SVG with jQuery .offset() not working in safari
此代码在 chrome
中运行良好
$("#el").hover(function () {
let position = $(this).offset();
$('#popover').css(position);
});
但是 offset() 在 safari 中总是 return 这个 :
{top: 0, left: 0}
#el 是一个 svg 圆
<circle id="el" cx="500" cy="153" r="50"></circle>
这是 jQuery 的问题吗?
工作示例:https://jsfiddle.net/82syz54m/1/
在 chrome 中:
在 Safari 中:
以下代码兼容所有浏览器:
$("#el").hover(function () {
const circle = document.getElementById('el').getBoundingClientRect();
const position = { left: circle.left, top: circle.top };
$('#popover').css(position);
console.log(position)
});
此代码在 chrome
中运行良好 $("#el").hover(function () {
let position = $(this).offset();
$('#popover').css(position);
});
但是 offset() 在 safari 中总是 return 这个 :
{top: 0, left: 0}
#el 是一个 svg 圆
<circle id="el" cx="500" cy="153" r="50"></circle>
这是 jQuery 的问题吗?
工作示例:https://jsfiddle.net/82syz54m/1/
在 chrome 中:
在 Safari 中:
以下代码兼容所有浏览器:
$("#el").hover(function () {
const circle = document.getElementById('el').getBoundingClientRect();
const position = { left: circle.left, top: circle.top };
$('#popover').css(position);
console.log(position)
});