用js html css 制作红心点赞按钮cid1055-网页前端设计

html

  1. <!DOCTYPE html>
  2. <html lang="en" dir="ltr">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>Love React Animation</title>
  6. <link rel="stylesheet" href="https://code.5g-o.com/wp-content/uploads/2020/03/style.css">
  7. <script src="https://code.jquery.com/jquery-3.4.1.js"></script>
  8. </head>
  9. <body>
  10. <div class="heart-btn">
  11. <div class="content">
  12. <span class="heart"></span>
  13. <span class="text">Like</span>
  14. <span class="numb"></span>
  15. </div>
  16. </div>
  17. <script>
  18. $(document).ready(function(){
  19. $('.content').click(function(){
  20. $('.content').toggleClass("heart-active")
  21. $('.text').toggleClass("heart-active")
  22. $('.numb').toggleClass("heart-active")
  23. $('.heart').toggleClass("heart-active")
  24. });
  25. });
  26. </script>
  27. </body>
  28. </html>
<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <title>Love React Animation</title>
    <link rel="stylesheet" href="https://code.5g-o.com/wp-content/uploads/2020/03/style.css">
    <script src="https://code.jquery.com/jquery-3.4.1.js"></script>
  </head>
  <body>
    <div class="heart-btn">
      <div class="content">
        <span class="heart"></span>
        <span class="text">Like</span>
        <span class="numb"></span>
      </div>
    </div>

    <script>
      $(document).ready(function(){
        $('.content').click(function(){
          $('.content').toggleClass("heart-active")
          $('.text').toggleClass("heart-active")
          $('.numb').toggleClass("heart-active")
          $('.heart').toggleClass("heart-active")
        });
      });
    </script>

  </body>
</html>

css

  1. @import url('https://fonts.googleapis.com/css?family=Montserrat:600&display=swap');
  2. body{
  3. font-family: tahoma;
  4. background: #000;
  5. color: #352e2a;
  6. background: #000;
  7. background-size: cover;
  8. background-position: center center;
  9. }
  10. .heart-btn{
  11. position: absolute;
  12. top: 50%;
  13. left: 50%;
  14. transform: translate(-50%,-50%);
  15. }
  16. .content{
  17. padding: 13px 16px;
  18. display: flex;
  19. border: 2px solid #eae2e1;
  20. border-radius: 5px;
  21. cursor: pointer;
  22. }
  23. .content.heart-active{
  24. border-color: #f9b9c4;
  25. background: #fbd0d8;
  26. }
  27. .heart{
  28. position: absolute;
  29. background: url("https://code.5g-o.com/wp-content/uploads/2020/03/img.png") no-repeat;
  30. background-position: left;
  31. background-size: 2900%;
  32. height: 90px;
  33. width: 90px;
  34. top: 50%;
  35. left: 21%;
  36. transform: translate(-50%,-50%);
  37. }
  38. .text{
  39. font-size: 21px;
  40. margin-left: 30px;
  41. color: grey;
  42. font-family: 'Montserrat',sans-serif;
  43. }
  44. .numb:before{
  45. content: '12';
  46. font-size: 21px;
  47. margin-left: 7px;
  48. font-weight: 600;
  49. color: #9C9496;
  50. font-family: sans-serif;
  51. }
  52. .numb.heart-active:before{
  53. content: '13';
  54. color: #000;
  55. }
  56. .text.heart-active{
  57. color: #000;
  58. }
  59. .heart.heart-active{
  60. animation: animate .8s steps(28) 1;
  61. background-position: right;
  62. }
  63. @keyframes animate {
  64. 0%{
  65. background-position: left;
  66. }
  67. 100%{
  68. background-position: right;
  69. }
  70. }
@import url('https://fonts.googleapis.com/css?family=Montserrat:600&display=swap');
  body{
             font-family: tahoma;
             background: #000;
             color: #352e2a;
             background: #000;
             background-size: cover;
             background-position: center center;
             
         }
     
.heart-btn{
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%,-50%);
}
.content{
  padding: 13px 16px;
  display: flex;
  border: 2px solid #eae2e1;
  border-radius: 5px;
  cursor: pointer;
}
.content.heart-active{
  border-color: #f9b9c4;
  background: #fbd0d8;
}
.heart{
  position: absolute;
  background: url("https://code.5g-o.com/wp-content/uploads/2020/03/img.png") no-repeat;
  background-position: left;
  background-size: 2900%;
  height: 90px;
  width: 90px;
  top: 50%;
  left: 21%;
  transform: translate(-50%,-50%);
}
.text{
  font-size: 21px;
  margin-left: 30px;
  color: grey;
  font-family: 'Montserrat',sans-serif;
}
.numb:before{
  content: '12';
  font-size: 21px;
  margin-left: 7px;
  font-weight: 600;
  color: #9C9496;
  font-family: sans-serif;
}
.numb.heart-active:before{
  content: '13';
  color: #000;
}
.text.heart-active{
  color: #000;
}
.heart.heart-active{
  animation: animate .8s steps(28) 1;
  background-position: right;
}
@keyframes animate {
  0%{
    background-position: left;
  }
  100%{
    background-position: right;
  }
}

 

在线演示


? 让链接同时具备两种打开方式

获取源码: Heart Animated Button CSS
下载数:55人次, 文件大小: 12.8 KB, 上传日期: 2020年-11 月-27日

公众号回复:gcode  获取解压密码

qrcode_for_gh_6ea2c28a1709_258 (1)

3,701 人查阅

类似文章