通过input来写点赞爱心颜色

1,这个方法是通过input来关联label的样式

2,input要隐藏,label显示,点击label时input被选中,label添加动画改变样式

3,背景图的定位要正确

4,代码

css代码

<style type="text/css">

.app{

width: 100px;

height: 100px;

}

input{

display: none;

}

.app-aix{

/*position: relative;*/

display: block;

width: 100%;

  height: 5rem;

}

/*背景图*/

.app-aix::before{

content: "";

display: block;

background: url(img/mbico.png) no-repeat;

background-size: 2.5rem auto;

width: 2.5rem;

height: 2.5rem;

}

/*动画定位背景图的位置*/ /*input未选中的状态*/

.app-box .app-aix::before {

background-position: 0 -2.5rem;

-webkit-animation-duration: 1s;

animation-duration: 1s;

-webkit-animation-fill-mode: both;

animation-fill-mode: both;

}

/*选中input时的状态动画*/

.app-box :checked~.app-aix::before {

background-position: 0 -5rem;

-webkit-animation: collecting .3s linear 0s;

animation: collecting 0.4s linear 0s;

}

/*动画变化过程*/

@-webkit-keyframes collecting {

0% {

-webkit-transform: scale(0);

}

66% {

-webkit-transform: scale(1.2);

}

100% {

-webkit-transform: scale(1);

}

}

@keyframes collecting {

0% {

transform: scale(0);

}

66% {

transform: scale(1.2);

}

100% {

transform: scale(1);

}

}

</style>

html代码

<div class="app">

    <span class="app-box">

            <input type="checkbox" name="" value="" id="proCollecter" />

            <label for="proCollecter" class="app-aix"></label>

    </span>

</div>



最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 1、通过CocoaPods安装项目名称项目信息 AFNetworking网络请求组件 FMDB本地数据库组件 SD...
    阳明AI阅读 16,038评论 3 119
  • 今天的冥想进步好大,气息畅通了好多,配合着太极呼吸法,通体舒泰。中午难得没瞌睡且一天精力尚佳。 上午上了一天的课,...
    蕊蕊啊阅读 1,599评论 0 0
  • 句将随兴得,兴不与人期。 多少感怀事,一时清雅诗。 野吟何激越,春醉未推辞。 细雨社燕子,轻风堤柳丝。 明知流水早...
    雪窗_武立之阅读 2,806评论 0 2
  • 潮湿的木头长木耳,寒湿的体质长肿瘤。 木耳摘了还会长,肿瘤切了也会长,因为环境不改变,该长的还得长。 想不长木耳,...
    沁墨m阅读 1,079评论 0 1