小程序 仿Twitter爱心点赞动画效果

本文介绍如何在微信小程序中创建一个模仿Twitter的爱心点赞动画效果,包含wxml、js和wxss代码实现细节,让点赞交互更加吸引用户。

wxml:

<view class="feed" >
  <view class="heart {{currentSelectTripType == 'like' ? 'active' : ''}}"  bindtap='addAnimateFun' data-id="like" style="background-position: {{cssAnimate}} left;"></view>
</view>

<view class="feed">
  <view class="heart {{currentSelectTripType == 'like2' ? 'active' : 'heartAnimation'}}"  bindtap='addAnimateFun2' data-id="like2" style="background-position: {{cssAnimate}} right;"></view>
</view> 

 js:


const app = getApp()

Page({

  data: {
    currentSelectTripType:'like'
  },

  addAnimateFun: function (e) {
    this.setData({
    currentSelectTripType: e.currentTarget.dataset.id
    })
  },
  addAnimateFun2:function(e){
    this.setData({
    currentSelectTripType: e.currentTarget.dataset.id
    })
  }

})

 

wxss:

.heart {
        background: url(http://www.ybpcn.com/skin/ybpcn/img/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;
    }

    .likeCount {
        font-family: 'Georgia', Times, Times New Roman, serif;
        margin-top: 32px;
        margin-left: 68px;
        font-size: 25px;
        color: #999999
    }

    @-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);
        
    }

    .active{
        display: none;
    }
    .feed{
      position: absolute;
      right:6rpx;
    }

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值