仿头条的点赞效果Html+css

觉得头条文章里面的点赞效果还是挺不错的,简单,简洁,和大部分主题都很搭,所以扒下来记住,以后方便整合使用

QQ图片20210907095918.png

html页面代码

  1. <button type="button" id="agree-btn" class="detail-like like">
  2. <div class="digg-icon"><div class="inner"><i></i></div></div>
  3. <span class="agree-num">1</span></button>

css样式代码

  1. .p_like button[disabled] .digg-icon{
  2. background: #fff2f2;
  3. }
  4. .p_like button[disabled] .digg-icon i {
  5. -webkit-transform-origin: -16% 66%;
  6. -moz-transform-origin: -16% 66%;
  7. transform-origin: -16% 66%;
  8. -webkit-animation: like .7s forwards;
  9. -moz-animation: like .7s forwards;
  10. animation: like .7s forwards;
  11. background-image: url(https://lf3-cdn2-tos.bytescm.com/toutiao/toutiao_web_pc/svgs/like_active.b265cb30.svg);
  12. }
  13. .p_like button[disabled] .agree-num{
  14. color: #f04142;
  15. }
  16. .detail-like {
  17. text-align: center;
  18. cursor: pointer;
  19. color: #222;
  20. outline: none;
  21. background: white;
  22. }
  23. .detail-like .digg-icon {
  24. position: relative;
  25. border-radius: 24px;
  26. width: 48px;
  27. height: 48px;
  28. background: #f8f8f8;
  29. }
  30. .detail-like .digg-icon .inner {
  31. position: absolute;
  32. top: 50%;
  33. left: 50%;
  34. -webkit-transform: translate(-50%,-50%);
  35. -moz-transform: translate(-50%,-50%);
  36. transform: translate(-50%,-50%);
  37. font-size: 0;
  38. }
  39. .detail-like .digg-icon i {
  40. display: block;
  41. width: 24px;
  42. height: 24px;
  43. background: url(https://lf3-cdn2-tos.bytescm.com/toutiao/toutiao_web_pc/svgs/like.0caed57a.svg) no-repeat 50%;
  44. background-size: contain;
  45. }
  46. .detail-like>span {
  47. display: inline-block;
  48. margin-top: 4px;
  49. font-size: 12px;
  50. line-height: 20px;
  51. }
  52. @-webkit-keyframes like {
  53. 0%,
  54. to {
  55. -webkit-transform: rotate(0deg);
  56. transform: rotate(0deg);
  57. -webkit-animation-timing-function: ease;
  58. animation-timing-function: ease
  59. }
  60. 20% {
  61. -webkit-transform: rotate(-20deg);
  62. transform: rotate(-20deg);
  63. -webkit-animation-timing-function: cubic-bezier(.66, 0, .34, 1);
  64. animation-timing-function: cubic-bezier(.66, 0, .34, 1)
  65. }
  66. 48% {
  67. -webkit-transform: rotate(8deg);
  68. transform: rotate(8deg);
  69. -webkit-animation-timing-function: ease-in-out;
  70. animation-timing-function: ease-in-out
  71. }
  72. 75% {
  73. -webkit-transform: rotate(-1deg);
  74. transform: rotate(-1deg);
  75. -webkit-animation-timing-function: ease;
  76. animation-timing-function: ease
  77. }
  78. }
  79. @-moz-keyframes like {
  80. 0%,
  81. to {
  82. -moz-transform: rotate(0deg);
  83. transform: rotate(0deg);
  84. -moz-animation-timing-function: ease;
  85. animation-timing-function: ease
  86. }
  87. 20% {
  88. -moz-transform: rotate(-20deg);
  89. transform: rotate(-20deg);
  90. -moz-animation-timing-function: cubic-bezier(.66, 0, .34, 1);
  91. animation-timing-function: cubic-bezier(.66, 0, .34, 1)
  92. }
  93. 48% {
  94. -moz-transform: rotate(8deg);
  95. transform: rotate(8deg);
  96. -moz-animation-timing-function: ease-in-out;
  97. animation-timing-function: ease-in-out
  98. }
  99. 75% {
  100. -moz-transform: rotate(-1deg);
  101. transform: rotate(-1deg);
  102. -moz-animation-timing-function: ease;
  103. animation-timing-function: ease
  104. }
  105. }
  106. @keyframes like {
  107. 0%,
  108. to {
  109. -webkit-transform: rotate(0deg);
  110. -moz-transform: rotate(0deg);
  111. transform: rotate(0deg);
  112. -webkit-animation-timing-function: ease;
  113. -moz-animation-timing-function: ease;
  114. animation-timing-function: ease
  115. }
  116. 20% {
  117. -webkit-transform: rotate(-20deg);
  118. -moz-transform: rotate(-20deg);
  119. transform: rotate(-20deg);
  120. -webkit-animation-timing-function: cubic-bezier(.66, 0, .34, 1);
  121. -moz-animation-timing-function: cubic-bezier(.66, 0, .34, 1);
  122. animation-timing-function: cubic-bezier(.66, 0, .34, 1)
  123. }
  124. 48% {
  125. -webkit-transform: rotate(8deg);
  126. -moz-transform: rotate(8deg);
  127. transform: rotate(8deg);
  128. -webkit-animation-timing-function: ease-in-out;
  129. -moz-animation-timing-function: ease-in-out;
  130. animation-timing-function: ease-in-out
  131. }
  132. 75% {
  133. -webkit-transform: rotate(-1deg);
  134. -moz-transform: rotate(-1deg);
  135. transform: rotate(-1deg);
  136. -webkit-animation-timing-function: ease;
  137. -moz-animation-timing-function: ease;
  138. animation-timing-function: ease
  139. }
  140. }

以上就是完整的代码案例,如果整合到typecho的点赞效果的话,可以参考这篇文章使用

typecho打造点赞功能(案例教程)

Typecho 默认是没有提供点赞相关的 API 的,需要涉及到数据库操作 编写函数 Typecho 提供了一个 functions.php,可以用来定义函数....

文章由官网发布,如若转载,请注明出处:https://www.veimoz.com/1048
3 条评论
4.1k

发表评论

已有 3 条评论

  1. qwuaz     Win 10 /    Chrome
    2022-01-06 16:38

    看着是挺好看的

    1. 【管理员】Vv     Win 10 /    Chrome
      2022-01-06 16:40

      @qwuaz

      简单实用而已,现在已经不喜欢很花哨的东西了,网站主要还是内容

!