好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

CSS鼠标跟随的原理

说明

1、鼠标跟随就是元素会跟随着鼠标的移动,而作出相对应的运动。

2、为了能够监控当前鼠标的位置,我们只需在页面上铺上元素即可。

实例

<div>
  <div></div>
  <div></div>
  <div></div>
  <div></div>
  ... // 100个
</div>
.g-container {
    position: relative;
    width: 100vw;
    height: 100vh;
}
 
.position {
    position: absolute;
    width: 10vw;
    height: 10vh;
}
 
@for $i from 0 through 100 {
    
    $x: $i % 10;
    $y: ($i - $x) / 10;
    
    .position:nth-child(#{$i + 1}) {
        top: #{$y * 10}vh;
        left: #{$x * 10}vw;
    }
 
    .position:nth-child(#{$i + 1}):hover {
        background: rgba(255, 155, 10, .5)
    }
}

以上就是CSS鼠标跟随的原理,希望对大家有所帮助。 更多编程基础知识学习: python学习网

本文教程操作环境:windows7系统、css3版,DELL G3电脑。

查看更多关于CSS鼠标跟随的原理的详细内容...

  阅读:35次