Apply hover from the cursor position

后端 未结 5 811
难免孤独
难免孤独 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:15

    function moveInner(e)
    {
      var inner = document.getElementById('inner');
     
      inner.style.top = (e.clientY-100)+"px";
      inner.style.left= (e.clientX-100)+"px";
    }
    .f {
      width: 200px;
      height: 200px;
      background-color: grey;
      position: fixed;
      border-radius: 100px;
    }
    
    .s {
      width: 100px;
      height: 100px;
      background-color: black;
      border-radius: 100px;
      margin: 75px 0px 0px 75px;
    
      position: absolute;
    }
    
    
    Please put the inner div outside the parent div
    And set the onmouseover for parent div to change inner div's position

提交回复
热议问题