Apply hover from the cursor position

后端 未结 5 820
难免孤独
难免孤独 2021-02-14 04:23

I need get hover effect in a div from the cursor position.

I have this html and css

5条回答
  •  别那么骄傲
    2021-02-14 05:03

    Here is a jQuery solution.

    $("div.f").mousemove(function(e) {
      $('div.s').css({
        left: e.clientX - 28,
        top: e.clientY - 24
      });
    });
    .f {
      width: 200px;
      height: 200px;
      background-color: grey;
      position: fixed;
      border-radius: 100px;
      /* comment or remove the overflow if necessary */
      overflow: hidden;
    }
    
    .s {
      position: absolute;
      width: 50px;
      height: 50px;
      background-color: black;
      border-radius: 100px;
    }
    
    

提交回复
热议问题