<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>jQuery给图片点赞效果+1动画特效</title> <style type="text/css"> /* CSS Document */ /*点赞*/ @-webkit-keyframes niceIn { 0% { opacity: 1; -webkit-transform: scale(1); transform: scale(1) } 50% { opacity: 1; -webkit-transform: scale(1.5); transform: scale(1.5) } 70% { -webkit-transform: scale(.8); transform: scale(.8) } 100% { opacity: 1; -webkit-transform: scale(1); transform: scale(1) } } @keyframes niceIn { 0% { opacity: 1; -webkit-transform: scale(1); -ms-transform: scale(1); transform: scale(1) } 50% { opacity: 1; -webkit-transform: scale(1.5); -ms-transform: scale(1.5); transform: scale(1.5) } 70% { -webkit-transform: scale(.8); -ms-transform: scale(.8); transform: scale(.8) } 100% { opacity: 1; -webkit-transform: scale(1); -ms-transform: scale(1); transform: scale(1) } } @-o-keyframes niceIn{ 0% { opacity: 1; -o-transform: scale(1); transform: scale(1) } 50% { opacity: 1; -o-transform: scale(1.5); transform: scale(1.5) } 70% { -o-transform: scale(.8); transform: scale(.8) } 100% { opacity: 1; -o-transform: scale(1); transform: scale(1) } } @-moz-keyframes niceIn{ 0% { opacity: 1; -moz-transform: scale(1); transform: scale(1) } 50% { opacity: 1; -moz-transform: scale(1.5); transform:scale(1.5) } 70% { -o-transform: scale(.8); transform: scale(.8) } 100% { opacity: 1; -moz-transform: scale(1); transform: scale(1) } } .niceIn { -webkit-animation:niceIn 0.8s .2s ease; -moz-animation:niceIn 0.8s .2s ease; -o-animation:niceIn 0.8s .2s ease; animation:niceIn 0.8s .2s ease; } </style> </head> <body style="padding-top:300px;padding-left: 48%"> <button class="btn">点我试试</button> </body> <script src="http://cdn.bootcss.com/jquery/1.11.0/jquery.min.js"></script> <script type="text/javascript"> (function ($) { $.extend({ tipsBox: function (options) { options = $.extend({ obj: null, //jq对象,要在那个html标签上显示 str: "+1", //字符串,要显示的内容;也可以传一段html,如: "<b style='font-family:Microsoft YaHei;'>+1</b>" startSize: "12px", //动画开始的文字大小 endSize: "30px", //动画结束的文字大小 interval: 600, //动画时间间隔 color: "red", //文字颜色 callback: function () { } //回调函数 }, options); $("body").append("<span class='num'>" + options.str + "</span>"); var box = $(".num"); var left = options.obj.offset().left + options.obj.width() / 2; var top = options.obj.offset().top - options.obj.height(); box.css({ "position": "absolute", "left": left + "px", "top": top + "px", "z-index": 9999, "font-size": options.startSize, "line-height": options.endSize, "color": options.color }); box.animate({ "font-size": options.endSize, "opacity": "0", "top": top - parseInt(options.endSize) + "px" }, options.interval, function () { box.remove(); options.callback(); }); } }); })(jQuery); function niceIn(prop){ prop.find('i').addClass('niceIn'); setTimeout(function(){ prop.find('i').removeClass('niceIn'); },1000); } $(function () { $(".btn").click(function () { $.tipsBox({ obj: $(this), str: "+1", callback: function () { } }); niceIn($(this)); }); }); </script> </html> 提示:你可以先修改部分代码再运行。 转载请注明:有爱前端 » jQuery给图片点赞效果+1动画特效 喜欢 (3)or分享 (0)