JavaScript/jQuery - offsetLeft and offsetTop

后端 未结 3 1972
余生分开走
余生分开走 2021-02-03 15:36

When hovering over a span I would like to get the offsetLeft and offsetTop values so I can make something hover near it. When I do this I get 0 for both values.

What is

3条回答
  •  灰色年华
    2021-02-03 16:17

    I think you should be able to do this:

    HTML

    some username

    jQuery

    jQuery('.get-close-to').hover(function() {
        var offset = jQuery(this).css('offset');
        alert( 'Left: ' + offset.left + '\nTop: ' + offset.top );
    });
    

提交回复
热议问题