前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >5分钟实现鼠标悬停效果,CSS3悬停效果

5分钟实现鼠标悬停效果,CSS3悬停效果

作者头像
AlbertYang
发布2020-12-29 10:10:24
2.1K0
发布2020-12-29 10:10:24
举报

font awesome 图标使用方法参考网站:

https://fontawesome.dashgame.com/

HTML:

代码语言:javascript
复制
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>鼠标悬停效果:微信公众号AlbertYang</title>
    <link rel="stylesheet" type="text/css" href="cursor.css" />
    <link href="//netdna.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
  </head>
  <body>
    <ul>
      <li><a href="#"><i class="fa fa-address-card"></i></a></li>
      <li><a href="#"><i class="fa fa-address-card"></i></a></li>
      <li><a href="#"><i class="fa fa-drivers-license-o"></i></a></li>
      <li><a href="#"><i class="fa fa-envelope-open-o"></i></a></li>
      <li><a href="#"><i class="fa fa-ravelry"></i></a></li>
      <li><a href="#"><i class="fa fa-snowflake-o"></i></a></li>
      <div class="cursor"></div>
    </ul>
    <script>
      const cursor = document.querySelector(".cursor");
      document.addEventListener('mousemove', (e) => {
        cursor.style.left = e.pageX + 'px';
        cursor.style.top = e.pageY + 'px';
      })
</script>
  </body>
</html>

cursor.css:

代码语言:javascript
复制
* {
  margin: 0;
  padding: 0;
}
 
body {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  background-color: azure;
}
 
ul {
  position: relative;
  display: flex;
}
 
ul li {
  list-style: none;
  margin: 0 30px;
}
 
ul li a {
  position: relative;
  display: inline-block;
  font-size: 2em;
  color: gray;
  transition: all 0.3s;
}
 
ul li:hover a {
  color: deepskyblue;
  transform: scale(1.5);
}
 
.cursor {
  position: fixed;
  width: 0;
  height: 0;
  border: 15px solid gray;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  transition: width 0.3s, height 0.3s;
}
 
ul li:hover~.cursor {
  width: 80px;
  height: 80px;
  border: 3px solid deepskyblue;
}

今天的学习就到这里了,由于本人能力和知识有限,如果有写的不对的地方,还请各位大佬批评指正。如果想继续学习提高,欢迎关注我,每天学习进步一点点,就是领先的开始,加油。如果觉得本文对你有帮助的话,欢迎转发,评论,点赞!!!

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2020-12-16,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 AlbertYang 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档