Home > OS >  Find position of an SVG with jQuery .offset() not working in safari
Find position of an SVG with jQuery .offset() not working in safari

Time:12-07

This code is working fine in chrome

    $("#el").hover(function () {
    let position = $(this).offset();
    $('#popover').css(position);
    });

But offset() always return this in safari :

{top: 0, left: 0}

#el is a svg circle

<circle id="el"  cx="500" cy="153" r="50"></circle>

Is this a problem with jQuery?

Working exemple : enter image description here

In Safari : enter image description here

CodePudding user response:

The code below is compatible with all browsers:

$("#el").hover(function () {
const circle = document.getElementById('el').getBoundingClientRect();
const position = { left: circle.left, top: circle.top };
$('#popover').css(position);
console.log(position)
});
  • Related