绚烂多彩的点赞效果

1. 今天模仿着一个大神写可以个绚烂多彩的点赞功能,希望能给需要的朋友们一些小小的帮助

看代码咯!代码中用到的图片

 

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>多彩的点赞效果</title>
		<style type="text/css">
			.container {
				width: 300px;
				height: 300px;
				margin:0 auto;
				text-align: center;
			}
			.starBox {
				width: 250px;
				height: 250px;
				position: relative;
			}
			.starBox span {
				display: inline-block;
				vertical-align: middle;
				margin-right: 10px;
				width: 50px;
				height: 50px;	
				float: left;		
			}
			.heart {
				position: absolute;
				left: -14px;
				background: url(web_heart_animation.png);
				background-repeat: no-repeat;
				background-position: left;
				background-size: 2900%;
				cursor: pointer;
			}
			@-webkit-keyframes startchange {
				0% {
					background-position: left;
				}
				100% {
					background-position: right;
				}
			}
			@keyframes startchange {
				0% {
					background-position: left;
				}
				100% {
					background-position: right;
				}
			}
			.heartChangeClass {
				display: inline-block;
				-webkit-animation-name: startchange;
				animation-name: startchange;
				-webkit-animation-duration: 0.8s; /*完成一个周期所用的时间*/
				animation-duration: 0.8s;
				-webkit-animation-iteration-count: 1; /*循环执行的次数*/
				animation-iteration-count: 1;
				-webkit-animation-timing-function: steps(28); /*从头到尾以相同的速度播放动画*/
				animation-timing-function: steps(28);
				background-position: right;
			}
			.likeCount {
				margin-top: 15px;
				margin-left: 8px;
			}
		</style>
	</head>
	<body>
		<div class="container">
			<h3>这是一个多彩的点赞效果查看效果!</h3>
			<div class="starBox">
				<span class="heart" id="like1" data-id="like"></span> 
				<span class="likeCount" id="likeCount1">12</span>
			</div>
		</div>
		<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.0.js"></script>
		<script type="text/javascript">
			$(document).ready(function () {
				$('body').on('click', '.heart', function () {
					var clickId = $(this).attr('data-id');
					var index = $(this).attr('id').split('like')[1];
					var clickTime = parseInt($('#likeCount'+ index).html());
					if(clickId == "like") {
						$(this).addClass('heartChangeClass').attr('data-id', 'unlike');
						$('#likeCount'+ index).html(clickTime + 1);
					}else {
						$(this).removeClass('heartChangeClass').attr('data-id', 'like');
						$('#likeCount'+ index).html(clickTime - 1);
						
					}
				});
			})
		</script>
	</body>
</html>

   谢谢大家!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值