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

系统管理员 2022-12-28 08:19 395阅读 0赞

视频:https://www.bilibili.com/video/BV1cy4y1D7mz

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

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

https://fontawesome.dashgame.com/

HTML:

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>鼠标悬停效果:微信公众号AlbertYang</title>
  6. <link rel="stylesheet" type="text/css" href="cursor.css" />
  7. <link href="//netdna.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
  8. </head>
  9. <body>
  10. <ul>
  11. <li><a href="#"><i class="fa fa-address-card"></i></a></li>
  12. <li><a href="#"><i class="fa fa-address-card"></i></a></li>
  13. <li><a href="#"><i class="fa fa-drivers-license-o"></i></a></li>
  14. <li><a href="#"><i class="fa fa-envelope-open-o"></i></a></li>
  15. <li><a href="#"><i class="fa fa-ravelry"></i></a></li>
  16. <li><a href="#"><i class="fa fa-snowflake-o"></i></a></li>
  17. <div class="cursor"></div>
  18. </ul>
  19. <script>
  20. const cursor = document.querySelector(".cursor");
  21. document.addEventListener('mousemove', (e) => {
  22. cursor.style.left = e.pageX + 'px';
  23. cursor.style.top = e.pageY + 'px';
  24. })
  25. </script>
  26. </body>
  27. </html>

cursor.css:

  1. * {
  2. margin: 0;
  3. padding: 0;
  4. }
  5. body {
  6. display: flex;
  7. justify-content: center;
  8. align-items: center;
  9. height: 100vh;
  10. background-color: azure;
  11. }
  12. ul {
  13. position: relative;
  14. display: flex;
  15. }
  16. ul li {
  17. list-style: none;
  18. margin: 0 30px;
  19. }
  20. ul li a {
  21. position: relative;
  22. display: inline-block;
  23. font-size: 2em;
  24. color: gray;
  25. transition: all 0.3s;
  26. }
  27. ul li:hover a {
  28. color: deepskyblue;
  29. transform: scale(1.5);
  30. }
  31. .cursor {
  32. position: fixed;
  33. width: 0;
  34. height: 0;
  35. border: 15px solid gray;
  36. border-radius: 50%;
  37. transform: translate(-50%, -50%);
  38. pointer-events: none;
  39. transition: width 0.3s, height 0.3s;
  40. }
  41. ul li:hover~.cursor {
  42. width: 80px;
  43. height: 80px;
  44. border: 3px solid deepskyblue;
  45. }

202012121242595.gif

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

发表评论

表情:
评论列表 (有 0 条评论,395人围观)

还没有评论,来说两句吧...

相关阅读