html5+CSS3红心点赞动画按钮效果

 时间:2024-10-11 18:57:05

1、新建html文档。

html5+CSS3红心点赞动画按钮效果

2、书写hmtl代码。<article class="htmleaf-container"><div id="container"> <h3>点击下面的红心查看效果!</h3> <div class="feed" id="feed1"> <p>W3C </p> <div class="heart " id="like1" rel="like"></div> <div class="likeCount" id="likeCount1">14</div> </div> <div class="feed" id="feed2"> <p>百度一下</p> <div class="heart" id="like2" rel="like"></div> <div class="likeCount" id="likeCount2">10</div> </div></div></article>

html5+CSS3红心点赞动画按钮效果

3、书写css代码。body { color: #333333; }#container { margin多唉捋胝: 0 auto; width: 900px; font-family: arial; }#container h3 { font-family: "Microsoft YaHei"; }.heart { background: url(../images/web_heart_animation.png); background-position: left; background-repeat: no-repeat; height: 100px; width: 100px; cursor: pointer; position: absolute; left: -14px; background-size: 2900%; }.heart:hover, .heart:focus { background-position: right; }@-webkit-keyframes heartBlast { 0% {background-position: left;}100% {background-position: right;}}@keyframes heartBlast { 0% {background-position: left;}100% {background-position: right;}}.heartAnimation { display: inline-block; -webkit-animation-name: heartBlast; animation-name: heartBlast; -webkit-animation-duration: .8s; animation-duration: .8s; -webkit-animation-iteration-count: 1; animation-iteration-count: 1; -webkit-animation-timing-function: steps(28); animation-timing-function: steps(28); background-position: right; }.feed p { font-family: "Microsoft YaHei", 'Georgia', Times, Times New Roman, serif; font-size: 25px; }.feed { clear: both; margin-bottom: :20px;height: 150px; position: relative; }a { color: #7ac9ed; }p { margin: 0px; padding: 0px; }.likeCount { font-family: 'Georgia', Times, Times New Roman, serif; margin-top: 32px; margin-left: 68px; font-size: 25px; color: #999999 }

html5+CSS3红心点赞动画按钮效果

4、书写并引用js代码。<script src="js/jquery-1.11.0.min.js" ></script><script>$(document).ready(function(){$('body').on("click",'.heart',function(){ var A=$(this).attr("id"); var B=A.split("like"); var messageID=B[1]; var C=parseInt($("#likeCount"+messageID).html()); $(this).css("background-position","") var D=$(this).attr("rel"); if(D === 'like') { $("#likeCount"+messageID).html(C+1); $(this).addClass("heartAnimation").attr("rel","unlike"); } else { $("#likeCount"+messageID).html(C-1); $(this).removeClass("heartAnimation").attr("rel","like"); $(this).css("background-position","left"); }});});</script>

html5+CSS3红心点赞动画按钮效果

5、代码整体结构。

html5+CSS3红心点赞动画按钮效果

6、查看效果。

html5+CSS3红心点赞动画按钮效果
html5+CSS3红心点赞动画按钮效果
  • 蒜香海带苗的做法
  • 海鲜美食-蟹黄烧卖的做法
  • 古代时冰糖葫芦只有山楂味的吗蚂蚁庄园
  • 冬季手部皮肤干燥怎么办
  • 协调办理机关办公用房建设项目立项报告函怎么写
  • 热门搜索
    少代会手抄报 防疫手抄报大全图片 五水共治手抄报 父亲节手抄报 心理健康手抄报模板 新年手抄报图片 中国梦的手抄报 小学二年级手抄报 向英雄致敬手抄报简单 欢乐中国年手抄报