{"id":3695,"date":"2013-09-30T19:12:17","date_gmt":"2013-09-30T11:12:17","guid":{"rendered":"http:\/\/www.zhangxinxu.com\/wordpress\/?p=3695"},"modified":"2019-06-06T15:02:49","modified_gmt":"2019-06-06T07:02:49","slug":"css3-animation-requestanimationframe-tween-%e5%8a%a8%e7%94%bb%e7%ae%97%e6%b3%95","status":"publish","type":"post","link":"https:\/\/www.zhangxinxu.com\/wordpress\/2013\/09\/css3-animation-requestanimationframe-tween-%e5%8a%a8%e7%94%bb%e7%ae%97%e6%b3%95\/","title":{"rendered":"CSS3\u52a8\u753b\u90a3\u4e48\u5f3a\uff0crequestAnimationFrame\u8fd8\u6709\u6bdb\u7ebf\u7528\uff1f"},"content":{"rendered":"<p>by <a href=\"https:\/\/www.zhangxinxu.com\/\">zhangxinxu<\/a> from <a href=\"https:\/\/www.zhangxinxu.com\/\">http:\/\/www.zhangxinxu.com<\/a><br \/>\n\u672c\u6587\u5730\u5740\uff1a<a href=\"https:\/\/www.zhangxinxu.com\/wordpress\/?p=3695\">https:\/\/www.zhangxinxu.com\/wordpress\/?p=3695<\/a><\/p>\n<p><meta name=\"referrer\" content=\"no-referrer\"><\/p>\n<h3>\u4e00\u3001\u54df\uff0crequestAnimationFrame, \u65b0\u540c\u5b66\uff0c\u5148\u81ea\u6211\u4ecb\u7ecd\u4e0b<\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/ww1.sinaimg.cn\/small\/4b4d632fgw1e93ouawd4vj204503r747.jpg\" width=\"149\" height=\"135\" alt=\"\u5927\u5bb6\u597d\" class=\"alignnone\" \/><br \/>\nHello, \u5927\u5bb6\u597d\uff0c\u6211\u5c31\u662f\u98ce\u59ff\u5353\u8d8a\uff0c\u4e07\u79cd\u8ff7\u4eba\u7684<code>requestAnimationFrame<\/code>\uff0c\u5475\u5475\u5475\u5475\u3002\u5f88\u9ad8\u5174\u548c\u5927\u5bb6\u89c1\u9762\uff0c\u8bf7\u591a\u6307\u6559\uff01<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/ww4.sinaimg.cn\/mw690\/4b4d632fgw1e94al1jwmsj204603e0sn.jpg\" width=\"150\" height=\"122\" alt=\"\u5e73\u9759\u7684\u4f17\u4eba\" class=\"alignnone\" \/><br \/>\n\u3002\u3002\u3002\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/ww1.sinaimg.cn\/mw690\/4b4d632fgw1e94b4k48m6j2046046wee.jpg\" width=\"150\" height=\"150\" alt=\"\u5c0f\u4e38\u5b50\u65e0\u5948\" class=\"alignnone\" \/><br \/>\n\u54b3\u54b3\uff0c\u5927\u5bb6\u4e0d\u8981\u4e00\u526f\u4e0d\u5c51\u7684\u6837\u5b50\u561b\u3002\u8ddf\u4f60\u8bb2\uff0c\u6211\u53ef\u662f\u5f88\u6709\u7528\u7684\u3002\u6240\u8c13\u4eba\u5982\u5176\u540d\uff0c\u770b\u6211\u540d\u5b57\u8fd9\u4e48\u957f\uff0c\u8868\u610f\u4e3a\u201c\u8bf7\u6c42\u52a8\u753b\u5e27\u201d\uff0c\u660e\u6446\u7740\u4e00\u526f\u5f88\u5c4c\u7684\u6837\u5b50\uff01<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/ww4.sinaimg.cn\/mw690\/4b4d632fgw1e94al1jwmsj204603e0sn.jpg\" width=\"150\" height=\"122\" alt=\"\u5e73\u9759\u7684\u4f17\u4eba\" class=\"alignnone\" \/><br \/>\n\u3002\u3002\u3002\u3002\u6309\u7167\u8fd9\u79cd\u8bf4\u6cd5\uff0c\u201c\u6a31\u6843\u5c0f\u4e38\u5b50\u201d\u5c31\u662f\u6a31\u6843\u505a\u7684\u4e38\u5b50\u54af\uff0c\u6069\uff0c\u770b\u8111\u888b\u786e\u5b9e\u86ee\u50cf\u7684~<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/ww1.sinaimg.cn\/mw690\/4b4d632fgw1e94bhy9wk3j203k03kjr9.jpg\" width=\"150\" height=\"150\" alt=\"\u6a31\u6843\u5c0f\u4e38\u5b50\u6c57\" class=\"alignnone\" \/><br \/>\n\u3002\u3002\u3002\u3002<\/p>\n<p>\u60f3\u5230\u660e\u5929\u5c31\u662f\u56fd\u5e86\u5927\u5047\uff0c\u4eca\u5929\u6211\u5c31\u5c0f\u4eba\u4e0d\u8bb0\u5927\u4eba\u8fc7\u3002\u7ed9\u4f60\u4eec\u6765\u526f\u9707\u7cbe\u7684\u56fe\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201309\/frame-lost.png\" width=\"408\" height=\"129\" alt=\"\u5e27\u4e22\u5931\u793a\u610f\" class=\"alignnone\" \/><\/p>\n<p>\u76f8\u5f53\u4e00\u90e8\u5206\u7684\u6d4f\u89c8\u5668\u7684\u663e\u793a\u9891\u7387\u662f<code>16.7ms<\/code>, \u5c31\u662f\u4e0a\u56fe\u7b2c\u4e00\u884c\u7684\u8282\u594f\uff0c\u8868\u73b0\u5c31\u662f\u201c\u6211\u548c\u4f60\u4e00\u6b65\u4e24\u6b65\u4e09\u6b65\u56db\u6b65\u5f80\u524d\u8d70\u2026\u2026\u201d\u3002\u5982\u679c\u6211\u4eec\u706b\u529b\u641e\u731b\u4e00\u70b9\uff0c\u4f8b\u5982\u641e\u4e2a<code>10ms<\/code> <code>setTimeout<\/code>\uff0c\u5c31\u4f1a\u662f\u4e0b\u9762\u4e00\u884c\u7684\u6a21\u6837\u2014\u2014\u6bcf\u7b2c\u4e09\u4e2a\u56fe\u5f62\u90fd\u65e0\u6cd5\u7ed8\u5236\uff08\u7ea2\u8272\u7bad\u5934\u6307\u793a\uff09\uff0c\u8868\u73b0\u5c31\u662f\u201c\u6211\u548c\u4f60\u4e00\u6b65\u4e24\u6b65 \u5751 \u56db\u6b65\u5f80\u524d\u8d70\u2026\u2026\u201d\u3002<\/p>\n<p>\u56ca\u7239(\u306a\u3093\u3067\u3088)\uff1f<\/p>\n<p>\u56fd\u5e86\u5317\u4eac\u9ad8\u901f\uff0c\u6700\u591a\u6bcf<code>16.7s<\/code>\u901a\u8fc7\u4e00\u8f86\u8f66\uff0c\u7ed3\u679c\uff0c\u7a81\u7136\u63d2\u5165\u4e00\u6279<code>setTimeout<\/code>\u7684\u519b\u8f66\uff0c\u5f3a\u884c\u8981<code>10s<\/code>\u901a\u8fc7\u3002\u663e\u7136\uff0c\u8fd9\u662f\u8d85\u8d1f\u8377\u7684\uff0c\u8981\u60f3\u987a\u5229\u8fdb\u884c\uff0c\u53ea\u80fd\u8ba9\u7b2c\u4e09\u8f86\u8f66\u76f4\u63a5\u6d88\u5931\uff08\u6b63\u5982\u663e\u793a\u7ed8\u5236\u7b2c\u4e09\u5e27\u7684\u4e22\u5931\uff09\u3002\u7136\uff0c\u8fd9\u662f\u4e0d\u73b0\u5b9e\u7684\uff0c\u4e8e\u662f\u5c31\u6709\u4e86\u4f1a\u5835\u8f66\uff01<\/p>\n<p>\u540c\u6837\u7684\uff0c\u663e\u793a\u5668<code>16.7ms<\/code><strong>\u5237\u65b0\u95f4\u9694\u4e4b\u524d\u53d1\u751f\u4e86\u5176\u4ed6\u7ed8\u5236\u8bf7\u6c42<\/strong>(<code>setTimeout<\/code>)\uff0c\u5bfc\u81f4\u6240\u6709\u7b2c\u4e09\u5e27\u4e22\u5931\uff0c\u7ee7\u800c\u5bfc\u81f4\u52a8\u753b\u65ad\u7eed\u663e\u793a\uff08\u5835\u8f66\u7684\u611f\u89c9\uff09\uff0c\u8fd9\u5c31\u662f\u8fc7\u5ea6\u7ed8\u5236\u5e26\u6765\u7684\u95ee\u9898\u3002\u4e0d\u4ec5\u5982\u6b64\uff0c\u8fd9\u79cd\u8ba1\u65f6\u5668\u9891\u7387\u7684\u964d\u4f4e\u4e5f\u4f1a\u5bf9\u7535\u6c60\u4f7f\u7528\u5bff\u547d\u9020\u6210\u8d1f\u9762\u5f71\u54cd\uff0c\u5e76\u4f1a\u964d\u4f4e\u5176\u4ed6\u5e94\u7528\u7684\u6027\u80fd\u3002<\/p>\n<p>\u8fd9\u4e5f\u662f\u4e3a\u4f55<code>setTimeout<\/code>\u7684\u5b9a\u65f6\u5668\u503c\u63a8\u8350\u6700\u5c0f\u4f7f\u7528<code>16.7ms<\/code>\u7684\u539f\u56e0\uff0816.7 = 1000 \/ 60, \u5373\u6bcf\u79d260\u5e27\uff09\u3002<\/p>\n<p>\u800c\u6211<code>requestAnimationFrame<\/code>\u5c31\u662f\u4e3a\u4e86\u8fd9\u4e2a\u800c\u51fa\u73b0\u7684\u3002\u6211\u6240\u505a\u7684\u4e8b\u60c5\u5f88\u7b80\u5355\uff0c\u8ddf\u7740\u6d4f\u89c8\u5668\u7684\u7ed8\u5236\u8d70\uff0c\u5982\u679c\u6d4f\u89c8\u8bbe\u5907\u7ed8\u5236\u95f4\u9694\u662f<code>16.7ms<\/code>\uff0c\u90a3\u6211\u5c31\u8fd9\u4e2a\u95f4\u9694\u7ed8\u5236\uff1b\u5982\u679c\u6d4f\u89c8\u8bbe\u5907\u7ed8\u5236\u95f4\u9694\u662f<code>10ms<\/code>, \u6211\u5c31<code>10ms<\/code>\u7ed8\u5236\u3002\u8fd9\u6837\u5c31\u4e0d\u4f1a\u5b58\u5728\u8fc7\u5ea6\u7ed8\u5236\u7684\u95ee\u9898\uff0c\u52a8\u753b\u4e0d\u4f1a\u6389\u5e27\uff0c\u81ea\u7136\u6d41\u7545\u7684\u8bf4~~ <\/p>\n<p>\u5185\u90e8\u662f\u8fd9\u4e48\u8fd0\u4f5c\u7684\uff1a<br \/>\n\u6d4f\u89c8\u5668\uff08\u5982\u9875\u9762\uff09\u6bcf\u6b21\u8981\u6d17\u6fa1\uff08\u91cd\u7ed8\uff09\uff0c\u5c31\u4f1a\u901a\u77e5\u6211(<code>requestAnimationFrame<\/code>)\uff1a\u5c0f\u4e38\u5b50\uff0c\u6211\u8981\u6d17\u6fa1\u4e86\uff0c\u4f60\u53ef\u4ee5\u8ddf\u6211\u4e00\u8d77\u6d17\u54e6\uff01<\/p>\n<p>\u8fd9\u662f\u8d44\u6e90\u975e\u5e38\u9ad8\u6548\u7684\u4e00\u79cd\u5229\u7528\u65b9\u5f0f\u3002\u600e\u4e48\u8bb2\u5462\uff1f<\/p>\n<ol>\n<li>\u5c31\u7b97\u5f88\u591a\u4e2a\u5c0f\u4e38\u5b50\u8981\u4e00\u8d77\u6d17\u6fa1\uff0c\u6d4f\u89c8\u5668\u53ea\u8981\u901a\u77e5\u4e00\u6b21\u5c31\u53ef\u4ee5\u4e86\u3002\u800c<code>setTimeout<\/code>\u8c8c\u4f3c\u662f\u591a\u4e2a\u72ec\u7acb\u7ed8\u5236\u3002<\/li>\n<li>\u9875\u9762\u6700\u5c0f\u5316\u4e86\uff0c\u6216\u8005\u88abTab\u5207\u6362\u5173\u706f\u4e86\u3002\u9875\u9762\u662f\u4e0d\u4f1a\u6d17\u6fa1\u7684\uff0c\u81ea\u7136\uff0c\u5c0f\u4e38\u5b50\u4e5f\u4e0d\u4f1a\u6d17\u6fa1\u7684\uff08\u6ca1\u901a\u77e5\u554a\uff09\u3002\u9875\u9762\u7ed8\u5236\u5168\u90e8\u505c\u6b62\uff0c\u8d44\u6e90\u9ad8\u6548\u5229\u7528\u3002<\/li>\n<\/ol>\n<p>\u80bf\u4e48\u6837\uff1f<code>requestAnimationFrame<\/code>\u6851\u9ebb\u6211\u679c\u7136\u662f\u4e07\u5343\u8ff7\u4eba\u7684\u5427\uff01\uff01<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/ww3.sinaimg.cn\/mw690\/4b4d632fgw1e94d3ohwnmj204603ga9y.jpg\" width=\"150\" height=\"124\" alt=\"\u4e0d\u9519\u54e6\uff0c\u56db\u57fa\u4f6c\u8868\u60c5\" class=\"alignnone\" \/><br \/>\n\u8036\uff01\u679c\u7136\u6709\u6599\uff0c\u4e0d\u662f\u770b\u4e0a\u53bb\u7684\u5e73\u677f\u7535\u8111\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/ww2.sinaimg.cn\/small\/4b4d632fgw1e94dzrv106j202s02s744.jpg\" width=\"150\" height=\"150\" alt=\"\u82b1\u75f4 \u5c0f\u4e38\u5b50\" class=\"alignnone\" \/><br \/>\n\u5537~\u5938\u5f97\u4eba\u5bb6\u90fd\u4e0d\u597d\u610f\u601d\u4e86\uff01<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/ww4.sinaimg.cn\/mw690\/4b4d632fgw1e94al1jwmsj204603e0sn.jpg\" width=\"150\" height=\"122\" alt=\"\u5e73\u9759\u7684\u4f17\u4eba\" class=\"alignnone\" \/><br \/>\n\u3002\u3002\u3002\u3002\u90a3\u4f60\u7684<strong>\u517c\u5bb9\u6027\u5982\u4f55<\/strong>\uff1f<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/ww1.sinaimg.cn\/small\/4b4d632fgw1e94e2lzuahj202r02qt8k.jpg\" width=\"150\" height=\"150\" alt=\"\u6211\u554a \u5c0f\u4e38\u5b50\" class=\"alignnone\" \/><br \/>\n\u6211\u7684\u517c\u5bb9\u6027\u554a~~ \u5b6c\uff0c\u89c1\u4e0b\u9762~<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/image.zhangxinxu.com\/image\/blog\/201309\/2013-09-30_120300.png\" width=\"580\" height=\"293\" alt=\"requestAnimationFrame\u7684\u517c\u5bb9\u6027\u8868 \u5f20\u946b\u65ed-\u946b\u7a7a\u95f4-\u946b\u751f\u6d3b\" class=\"alignnone\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/ww4.sinaimg.cn\/mw690\/4b4d632fgw1e94al1jwmsj204603e0sn.jpg\" width=\"150\" height=\"122\" alt=\"\u5e73\u9759\u7684\u4f17\u4eba\" class=\"alignnone\" \/><br \/>\nAndroid\u8bbe\u5907\u538b\u6839\u5c31\u4e0d\u652f\u6301\u561b\uff01\u5176\u4ed6\u8bbe\u5907\u57fa\u672c\u4e0a\u8ddfCSS3\u52a8\u753b\u7684\u652f\u6301\u4e00\u6a21\u4e00\u6837\u561b\u3002<\/p>\n<p>\u6211\u8bf4\u5c0f\u7f8e\u5973\uff0c\u636e\u6211\u6240\u77e5\uff0cCSS3 <code>transition<\/code>\u6216<code>animation<\/code>\u52a8\u753b\u4e5f\u662f\u8d70\u7684\u8ddf\u4f60\u4e00\u6837\u7684\u7ed8\u5236\u539f\u7406\uff08<strong>\u8865\u5145\u4e8e2013-10-09<\/strong>\uff1a\u6839\u636e\u81ea\u5df1\u540e\u6765\u7684\u6d4b\u8bd5\uff0c\u53d1\u73b0\uff0cCSS3\u52a8\u753b\u5728Tab\u5207\u6362\u56de\u6765\u7684\u65f6\u5019\uff0c\u52a8\u753b\u8868\u73b0\u5e76\u4e0d\u6682\u505c\uff1b\u901a\u8fc7Chrome frames\u5de5\u5177\u6d4b\u8bd5\u53d1\u73b0\uff0cTab\u5207\u6362\u4e4b\u540e\uff0c\u8ba1\u7b97\u6e32\u67d3\u7ed8\u5236\u90fd\u505c\u6b62\uff0cTab\u5207\u6362\u56de\u6765\u65f6\u4f3c\u4e4e\u901a\u8fc7\u5185\u7f6eJS\u8ba1\u7b97\u4e86\u52a8\u753b\u4f4d\u7f6e\u5b9e\u73b0\u91cd\u7ed8\uff0c\u9020\u6210\u52a8\u753b\u4e0d\u6682\u505c\u7684\u611f\u89c9\uff09\u3002\u4f46\u662f\u4eba\u5bb6\u7684\u5b9e\u73b0\u8f7b\u677e\u5f88\u591a\u554a\uff0c\u800c\u4e14\u76f8\u5f53\u5f3a\u5927\uff0c\u90a3\u4f60\u8fd8\u6709\u4e2a\u6bdb\u7ebf\u7528\uff01\u4f60\u8be5\u60f3\u60f3\u4f60\u4e00\u76f4\u9c9c\u6709\u4eba\u95ee\u6d25\u7684\u539f\u56e0\u4e86\uff01<\/p>\n<h3>\u4e8c\u3001\u53cd\u51fb\u5427\uff0crequestAnimationFrame\u540c\u5b66<\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/ww1.sinaimg.cn\/mw690\/4b4d632fgw1e94i9sr8x4j202s02sa9w.jpg\" width=\"150\" height=\"150\" alt=\"\u53cd\u51fb\" class=\"alignnone\" \/><br \/>\n\u57fa\u4f6c\u4eec\uff0c\u4f60\u4eec\u7684\u773c\u754c\u592a\u72ed\u9698\u4e86\uff0c\u89c2\u70b9\u592a\u80a4\u6d45\u7684\u3002\u9996\u5148\u4ece\u54f2\u5b66\u5b8f\u89c2\u8bb2\uff0c\u4e8b\u7269\u5b58\u5728\u5fc5\u6709\u5176\u9053\u7406\u3002\u56e0\u6b64\uff0c\u672c\u5927\u4eba\u80af\u5b9a\u662f\u6709\u4ef7\u503c\u7684\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/ww4.sinaimg.cn\/mw690\/4b4d632fgw1e94al1jwmsj204603e0sn.jpg\" width=\"150\" height=\"122\" alt=\"\u5e73\u9759\u7684\u4f17\u4eba\" class=\"alignnone\" \/><br \/>\n\u90a3\u4f60\u5230\u8bf4\u8bf4\u4f60\u6709\u7eb3\u5c3c\u4ef7\u503c~~~<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/ww1.sinaimg.cn\/mw690\/4b4d632fgw1e94i9sr8x4j202s02sa9w.jpg\" width=\"150\" height=\"150\" alt=\"\u53cd\u51fb\" class=\"alignnone\" \/><br \/>\n\u51c6\u5907\u597d\u4e86\u6728\u6709\uff0c\u5f85\u4f1a\u513f\u8bf4\u51fa\u6765\u5413\u6b7b\u4f60\u4eec\u3002\u542c\u597d\u4e86\uff0c\u8db3\u8db3\u67093\u5927\u70b9\uff1a<br \/>\n<strong>1. \u7edf\u4e00\u7684\u5411\u4e0b\u517c\u5bb9\u7b56\u7565<\/strong><br \/>\n\u867d\u8bf4CSS3\u5b9e\u73b0\u52a8\u753b\u5373\u9ad8\u6548\u53c8\u65b9\u4fbf\uff0c\u4f46\u662f\u5bf9\u4e8ePC\u6d4f\u89c8\u5668\uff0cIE8, IE9\u4e4b\u6d41\uff0c\u4f60\u60f3\u517c\u5bb9\u5b9e\u73b0\u67d0\u4e9b\u52a8\u753b\u6548\u679c\uff0c\u6bd4\u65b9\u8bf4\u6de1\u5165\u6de1\u51fa\uff0c\u6562\u95ee\uff0c\u4f60\u600e\u4e48\u5b9e\u73b0\uff1f<\/p>\n<p>\u770b\u4f60\u4eec\u90a3\u526f\u5446\u82e5\u6728\u9e21\u7684\u8868\u60c5\u5c31\u77e5\u9053\u4e86\uff0cIE10+ CSS3\u5b9e\u73b0\uff0cIE9-\u4e4b\u6d41JS <code>setTimeout<\/code>\u5b9e\u73b0\uff0c\u6211\u8bf4\u7d2f\u4e0d\u7d2f\u554a\uff0c\u4e24\u5957\u5b8c\u5168\u4e0d\u540c\u7684style. \u4f60\u6539\u4e0b\u52a8\u753b\u65f6\u95f4\u662f\u4e0d\u662f\u8981\u6539\u4e24\u5904\uff1f\u4f46\u662f\u6211<code>requestAnimationFrame<\/code>\u8ddf<code>setTimeout<\/code>\u975e\u5e38\u7c7b\u4f3c\uff0c\u90fd\u662f\u5355\u56de\u8c03\uff0c\u7528\u6cd5\u4e5f\u7c7b\u4f3c\u3002<\/p>\n<div class=\"zxx_code\">\n<pre>var handle = setTimeout(renderLoop, PERIOD);<\/pre>\n<\/div>\n<div class=\"zxx_code\">\n<pre>var handle = requestAnimationFrame(renderLoop);<\/pre>\n<\/div>\n<p>\u6211<code>requestAnimationFrame<\/code>\u8c03\u7528\u4e00\u6b21\u53ea\u4f1a\u91cd\u7ed8\u4e00\u6b21\u52a8\u753b\uff0c\u56e0\u6b64\uff0c\u5982\u679c\u60f3\u8981\u5b9e\u73b0\u8054\u7cfb\u52a8\u753b\uff0c\u5c31\u4f7f\u7528<code>renderLoop<\/code>\u53cd\u590d\u8e42\u8e8f\u6211\u5427~<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/image.zhangxinxu.com\/image\/blog\/201309\/2013-09-30_145801.png\" width=\"240\" height=\"262\" alt=\"\u53d7\u8650\" class=\"alignnone\" \/><\/p>\n<p>So\uff0c\u5982\u679c\u60f3\u8981\u7b80\u5355\u7684\u517c\u5bb9\uff0c\u53ef\u4ee5\u8fd9\u6837\u5b50\uff1a<\/p>\n<div class=\"zxx_code\">\n<pre>window.requestAnimFrame = (function(){\r\n  return  window.requestAnimationFrame       ||\r\n          window.webkitRequestAnimationFrame ||\r\n          window.mozRequestAnimationFrame    ||\r\n          function( callback ){\r\n            window.setTimeout(callback, 1000 \/ 60);\r\n          };\r\n})();\r\n<\/pre>\n<\/div>\n<p>\u4f46\u662f\u5462\uff0c\u5e76\u4e0d\u662f\u6240\u6709\u8bbe\u5907\u7684\u7ed8\u5236\u65f6\u95f4\u95f4\u9694\u662f<code>1000\/60 ms<\/code>, \u4ee5\u53ca\u4e0a\u9762\u5e76\u6728\u6709cancel\u76f8\u5173\u65b9\u6cd5\uff0c\u6240\u4ee5\uff0c\u5c31\u6709\u4e0b\u9762\u8fd9\u4efd\u66f4\u5168\u9762\u7684\u517c\u5bb9\u65b9\u6cd5\uff1a<\/p>\n<div class=\"zxx_code\">\n<pre>(function() {\r\n    var lastTime = 0;\r\n    var vendors = ['webkit', 'moz'];\r\n    for(var x = 0; x < vendors.length &#038;&#038; !window.requestAnimationFrame; ++x) {\r\n        window.requestAnimationFrame = window[vendors[x] + 'RequestAnimationFrame'];\r\n        window.cancelAnimationFrame = window[vendors[x] + 'CancelAnimationFrame'] ||    <span style=\"color:green;\">\/\/ Webkit\u4e2d\u6b64\u53d6\u6d88\u65b9\u6cd5\u7684\u540d\u5b57\u53d8\u4e86<\/span>\r\n                                      window[vendors[x] + 'CancelRequestAnimationFrame'];\r\n    }\r\n\r\n    if (!window.requestAnimationFrame) {\r\n        window.requestAnimationFrame = function(callback, element) {\r\n            var currTime = new Date().getTime();\r\n            var timeToCall = Math.max(0, 16.7 - (currTime - lastTime));\r\n            var id = window.setTimeout(function() {\r\n                callback(currTime + timeToCall);\r\n            }, timeToCall);\r\n            lastTime = currTime + timeToCall;\r\n            return id;\r\n        };\r\n    }\r\n    if (!window.cancelAnimationFrame) {\r\n        window.cancelAnimationFrame = function(id) {\r\n            clearTimeout(id);\r\n        };\r\n    }\r\n}());<\/pre>\n<\/div>\n<p>\u4e0aJS\u53ef<a href=\"https:\/\/www.zhangxinxu.com\/study\/201309\/requestAnimationFrame.js\" target=\"_blank\" class=\"a_link\">\u70b9\u51fb\u8fd9\u91cc<\/a>\u4e0b\u8f7d\u3002<\/p>\n<p>\u7136\u540e\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u4ee5\u4f7f\u7528<code>setTimeout<\/code>\u7684\u8c03\u8c03\u4f7f\u7528<code>requestAnimationFrame<\/code>\u65b9\u6cd5\u5566\uff0cIE6\u4e5f\u80fd\u652f\u6301\u54e6\uff01<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/ww3.sinaimg.cn\/mw690\/4b4d632fgw1e94d3ohwnmj204603ga9y.jpg\" width=\"150\" height=\"124\" alt=\"\u4e0d\u9519\u54e6\uff0c\u56db\u57fa\u4f6c\u8868\u60c5\" class=\"alignnone\" \/><br \/>\n\u8036\u8036\u8036\uff01\u2026\u2026<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/ww1.sinaimg.cn\/mw690\/4b4d632fgw1e94jtxpvjij202r02r745.jpg\" width=\"150\" height=\"150\" alt=\"\u627f\u8499\u8d4f\u8bc6 \u5c0f\u4e38\u5b50\" class=\"alignnone\" \/><br \/>\n\u591a\u8c22\u6367\u573a\uff01(*^__^*) \u563b\u563b\u2026\u2026<\/p>\n<p><strong>2. CSS3\u52a8\u753b\u4e0d\u80fd\u5e94\u7528\u6240\u6709\u5c5e\u6027<\/strong><br \/>\n\u4f7f\u7528CSS3\u52a8\u753b\u53ef\u4ee5\u6539\u53d8\u9ad8\u5bbd\uff0c\u65b9\u4f4d\uff0c\u89d2\u5ea6\uff0c\u900f\u660e\u5ea6\u7b49\u7b49\u3002\u4f46\u662f\uff0c\u5c31\u50cf\u516d\u9053\u5e26\u571f\u4e5f\u6709\u5f31\u70b9\u4e00\u6837\uff0cCSS3\u52a8\u753b\u4e5f\u6709\u5c5e\u6027\u97ad\u957f\u83ab\u53ca\u3002\u6bd4\u65b9\u8bf4<code>scrollTop<\/code>\u503c\u3002\u5982\u679c\u6211\u4eec\u5e0c\u671b\u8fd4\u56de\u9876\u90e8\u662f\u4e2a\u5e73\u6ed1\u6eda\u52a8\u6548\u679c\uff0c\u5c31\u76ee\u524d\u800c\u8a00\uff0cCSS3\u4f3c\u4e4e\u662f\u65e0\u80fd\u4e3a\u529b\u7684\u3002\u6b64\u65f6\uff0c\u8fd8\u662f\u8981JS\u51fa\u9a6c\uff0c\u52bf\u5fc5\uff0c\u6211<code>requestAnimationFrame<\/code>\u5927\u4eba\u5c31\u53ef\u4ee5\u5927\u653e\u5f02\u5f69\uff0c\u4e07\u4f17\u77a9\u76ee\u5566\uff0c\u54c8\u54c8\u54c8\u54c8\u54c8\u54c8\u54c8~~<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/ww1.sinaimg.cn\/mw690\/4b4d632fgw1e8d0cwhjtpg206n045tm6.gif\" width=\"239\" height=\"149\" alt=\"\u54c8\u54c8\u54c8\u54c8~~\" class=\"alignnone\" \/><\/p>\n<p>\u6bd4\u65b9\u8bf4\u70b9\u4e0b\u9762\u8fd9\u4e2a\u6309\u94ae\uff0c\u6eda\u4e0a\u53bb\u518d\u6eda\u4e0b\u6765\uff0c\u54c8\u54c8~<br \/>\n<input type=\"button\" id=\"scrollButton\" value=\"\u70b9\u51fb\u6211\uff0c\u770b\u89c1\u6211\u6ca1\u6709\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\"><br \/>\n<script src=\"http:\/\/www.zhangxinxu.com\/study\/201309\/requestAnimationFrame.js\"><\/script><br \/>\n<script>document.getElementById(\"scrollButton\").onclick = function() {var nowScroll = document.body.scrollTop || document.documentElement.scrollTop, flag = \"up\";var funScroll = function() {var top = document.body.scrollTop || document.documentElement.scrollTop;if (flag == \"up\") {top -= 20;if (top <=0) {top = 0; flag = \"down\";}} else if (flag == \"down\") {top += 20;if(top >= nowScroll) {top = nowScroll;  flag = \"stop\";}} else {return; }document.body.scrollTop = top;document.documentElement.scrollTop = top;requestAnimationFrame(funScroll);};if (nowScroll) {funScroll()};\t};<\/script><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/ww3.sinaimg.cn\/mw690\/4b4d632fgw1e94d3ohwnmj204603ga9y.jpg\" width=\"150\" height=\"124\" alt=\"\u4e0d\u9519\u54e6\uff0c\u56db\u57fa\u4f6c\u8868\u60c5\" class=\"alignnone\" \/><br \/>\n\u54df\u54df\u54df\uff0c\u4e0d\u9519\u4e0d\u9519\uff0c\u522e\u76ee\u76f8\u770b\u554a\uff0c\u4e38\u5b50~~<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/ww1.sinaimg.cn\/mw690\/4b4d632fgw1e94jtxpvjij202r02r745.jpg\" width=\"150\" height=\"150\" alt=\"\u627f\u8499\u8d4f\u8bc6 \u5c0f\u4e38\u5b50\" class=\"alignnone\" \/><br \/>\n\u4eba\u5bb6\u4e0d\u7981\u5938\u7684\u5566~~<\/p>\n<p><strong>3. CSS3\u652f\u6301\u7684\u52a8\u753b\u6548\u679c\u6709\u9650<\/strong><br \/>\n\u7531\u4e8eCSS3\u52a8\u753b\u7684\u8d1d\u585e\u5c14\u66f2\u7ebf\u662f\u4e00\u4e2a\u6807\u51c63\u6b21\u65b9\u66f2\u7ebf\uff08\u8be6\u89c1\uff1a<a href=\"http:\/\/www.zhangxinxu.com\/wordpress\/?p=3626\">\u8d1d\u585e\u5c14\u66f2\u7ebf\u4e0eCSS3\u52a8\u753b\u3001SVG\u548ccanvas\u7684\u57fa\u60c5<\/a>\uff09\uff0c\u56e0\u6b64\uff0c\u53ea\u80fd\u662f\uff1a<code>Linear<\/code>, <code>Sine<\/code>, <code>Quad<\/code>, <code>Cubic<\/code>, <code>Expo<\/code>\u7b49\uff0c\u4f46\u5bf9\u4e8e<code>Back<\/code>, <code>Bounce<\/code>\u7b49\u7f13\u52a8\u5219\u53ea\u53ef\u89c2\u671b\u800c\u4e0d\u53ef\u4eb5\u73a9\u7109\u3002 <\/p>\n<p>\u4e0b\u9762\u8fd9\u5f20\u56fe\u7785\u7785\uff0c\u90a3\u4e9b\u6ce2\u6f9c\u58ee\u9614\u7684\u66f2\u7ebf\u90fd\u662fCSS3\u6728\u6709\u7684~~<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/image.zhangxinxu.com\/image\/blog\/201309\/2013-09-30_170002.png\" width=\"580\" height=\"398\" alt=\"\u52a8\u753b\u66f2\u7ebf\u5927\u5168 \u5f20\u946b\u65ed-\u946b\u7a7a\u95f4-\u946b\u751f\u6d3b\" class=\"alignnone\" \/><\/p>\n<p>\u548b\u529e\uff0c\u548b\u529e\uff1f\u53ea\u80fd\u662fJS\u5b9e\u73b0\u5566\uff0c\u4e8e\u662f\uff0c\u672c\u5927\u4eba\u6211<code>requestAnimationFrame<\/code>\u53ef\u4ee5\u518d\u4e00\u6b21\u5927\u653e\u5f02\u5f69\u5566\uff0c\u554a\u54c8\u54c8\u54c8\uff01<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/ww4.sinaimg.cn\/mw690\/4b4d632fgw1e94al1jwmsj204603e0sn.jpg\" width=\"150\" height=\"122\" alt=\"\u5e73\u9759\u7684\u4f17\u4eba\" class=\"alignnone\" \/><br \/>\n\u5f97\u610f\u7684\u592a\u65e9\u4e86\u5427\uff0c\u8fd9\u4e9b\u52a8\u753b\u66f2\u7ebf\u770b\u4e0a\u53bb\u5f88\u590d\u6742\uff0c\u5076\u4eec\u663e\u7136\u9a7e\u9a6d\u4e0d\u4e86\u4e86\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/ww2.sinaimg.cn\/mw690\/4b4d632fgw1e94mzky6z8j202s02sq2s.jpg\" width=\"150\" height=\"150\" alt=\"\u4e86\u4e0d\u8d77 \u4e38\u5b50\" class=\"alignnone\" \/><br \/>\n\u5c31\u77e5\u9053\u4f60\u4eec\u8fd9\u4e9b\u57fa\u4f6c\u4e2d\u770b\u4e0d\u4e2d\u7528\u3002\u5148\u7ed9\u5927\u5bb6\u666e\u53ca\u4e0b\u7f13\u52a8(Tween)\u77e5\u8bc6\u5427\uff1a<\/p>\n<ul>\n<li>Linear\uff1a\u65e0\u7f13\u52a8\u6548\u679c<\/li>\n<li>Quadratic\uff1a\u4e8c\u6b21\u65b9\u7684\u7f13\u52a8\uff08t^2\uff09<\/li>\n<li>Cubic\uff1a\u4e09\u6b21\u65b9\u7684\u7f13\u52a8\uff08t^3\uff09<\/li>\n<li>Quartic\uff1a\u56db\u6b21\u65b9\u7684\u7f13\u52a8\uff08t^4\uff09<\/li>\n<li>Quintic\uff1a\u4e94\u6b21\u65b9\u7684\u7f13\u52a8\uff08t^5\uff09<\/li>\n<li>Sinusoidal\uff1a\u6b63\u5f26\u66f2\u7ebf\u7684\u7f13\u52a8\uff08sin(t)\uff09<\/li>\n<li>Exponential\uff1a\u6307\u6570\u66f2\u7ebf\u7684\u7f13\u52a8\uff082^t\uff09<\/li>\n<li>Circular\uff1a\u5706\u5f62\u66f2\u7ebf\u7684\u7f13\u52a8\uff08sqrt(1-t^2)\uff09<\/li>\n<li>Elastic\uff1a\u6307\u6570\u8870\u51cf\u7684\u6b63\u5f26\u66f2\u7ebf\u7f13\u52a8<\/li>\n<li>\u8d85\u8fc7\u8303\u56f4\u7684\u4e09\u6b21\u65b9\u7f13\u52a8\uff08(s+1)*t^3 &#8211; s*t^2\uff09<\/li>\n<li>\u6307\u6570\u8870\u51cf\u7684\u53cd\u5f39\u7f13\u52a8<\/li>\n<\/ul>\n<p>\u6bcf\u4e2a\u6548\u679c\u90fd\u5206\u4e09\u4e2a\u7f13\u52a8\u65b9\u5f0f\uff0c\u5206\u522b\u662f\uff08\u53ef\u91c7\u7528\u540e\u9762\u7684\u90aa\u6076\u8bb0\u5fc6\u6cd5\u5e2e\u52a9\u8bb0\u5fc6\uff09\uff1a<\/p>\n<ul>\n<li>easeIn\uff1a\u4ece0\u5f00\u59cb\u52a0\u901f\u7684\u7f13\u52a8\uff0c\u60f3\u8c61OOXX\u8fdb\u53bb\uff0c\u63a2\u8def\u8981\u82b1\u65f6\u95f4\uff0c\u56e0\u6b64\u80af\u5b9a\u662f\u5148\u6162\u540e\u5feb\u7684\uff1b<\/li>\n<li>easeOut\uff1a\u51cf\u901f\u52300\u7684\u7f13\u52a8\uff0c\u60f3\u8c61OOXX\u51fa\u6765\uff0c\u80af\u5b9a\u5b9a\u5148\u5feb\u540e\u6162\u7684\uff0c\u4ee5\u9632\u6389\u51fa\u6765\uff1b<\/li>\n<li>easeInOut\uff1a\u524d\u534a\u6bb5\u4ece0\u5f00\u59cb\u52a0\u901f\uff0c\u540e\u534a\u6bb5\u51cf\u901f\u52300\u7684\u7f13\u52a8\uff0c\u60f3\u8c61OOXX\u8fdb\u8fdb\u51fa\u51fa\uff0c\u5148\u6162\u540e\u5feb\u7136\u540e\u518d\u6162\u3002<\/li>\n<\/ul>\n<p>\u6bcf\u5468\u52a8\u753b\u6548\u679c\u90fd\u6709\u5176\u81ea\u8eab\u7684\u7b97\u6cd5\u3002\u6211\u4eec\u90fd\u77e5\u9053jQuery UI\u4e2d\u5c31\u6709\u7f13\u52a8\uff0cAs\u811a\u672c\u4e5f\u5185\u7f6e\u4e86\u7f13\u52a8\uff0c\u5176\u4e2d\u7684\u8fd0\u52a8\u7b97\u6cd5\u90fd\u662f\u4e00\u81f4\u7684\u3002\u6211\u7279\u610f\u5f04\u4e86\u4e00\u4efd\uff0c\u54e6\u5475\u5475\u5475~~\uff08\u56e0\u4e3a\u8f83\u9ad8\uff0c\u6eda\u52a8\u663e\u793a\uff09\uff0c\u6216<a href=\"https:\/\/github.com\/zhangxinxu\/Tween\/blob\/master\/tween.js\">GitHub\u8bbf\u95ee<\/a>\uff1a<\/p>\n<div class=\"zxx_code\" style=\"overflow:auto; height:400px; resize:vertical;\">\n<pre><span style=\"color:green;\">\/*\r\n * Tween.js\r\n * t: current time\uff08\u5f53\u524d\u65f6\u95f4\uff09\r\n * b: beginning value\uff08\u521d\u59cb\u503c\uff09\r\n * c: change in value\uff08\u53d8\u5316\u91cf\uff09\r\n * d: duration\uff08\u6301\u7eed\u65f6\u95f4\uff09\r\n*\/<\/span>\r\nvar Tween = {\r\n    Linear: function(t, b, c, d) { return c*t\/d + b; },\r\n    Quad: {\r\n        easeIn: function(t, b, c, d) {\r\n            return c * (t \/= d) * t + b;\r\n        },\r\n        easeOut: function(t, b, c, d) {\r\n            return -c *(t \/= d)*(t-2) + b;\r\n        },\r\n        easeInOut: function(t, b, c, d) {\r\n            if ((t \/= d \/ 2) < 1) return c \/ 2 * t * t + b;\r\n            return -c \/ 2 * ((--t) * (t-2) - 1) + b;\r\n        }\r\n    },\r\n    Cubic: {\r\n        easeIn: function(t, b, c, d) {\r\n            return c * (t \/= d) * t * t + b;\r\n        },\r\n        easeOut: function(t, b, c, d) {\r\n            return c * ((t = t\/d - 1) * t * t + 1) + b;\r\n        },\r\n        easeInOut: function(t, b, c, d) {\r\n            if ((t \/= d \/ 2) < 1) return c \/ 2 * t * t*t + b;\r\n            return c \/ 2*((t -= 2) * t * t + 2) + b;\r\n        }\r\n    },\r\n    Quart: {\r\n        easeIn: function(t, b, c, d) {\r\n            return c * (t \/= d) * t * t*t + b;\r\n        },\r\n        easeOut: function(t, b, c, d) {\r\n            return -c * ((t = t\/d - 1) * t * t*t - 1) + b;\r\n        },\r\n        easeInOut: function(t, b, c, d) {\r\n            if ((t \/= d \/ 2) < 1) return c \/ 2 * t * t * t * t + b;\r\n            return -c \/ 2 * ((t -= 2) * t * t*t - 2) + b;\r\n        }\r\n    },\r\n    Quint: {\r\n        easeIn: function(t, b, c, d) {\r\n            return c * (t \/= d) * t * t * t * t + b;\r\n        },\r\n        easeOut: function(t, b, c, d) {\r\n            return c * ((t = t\/d - 1) * t * t * t * t + 1) + b;\r\n        },\r\n        easeInOut: function(t, b, c, d) {\r\n            if ((t \/= d \/ 2) < 1) return c \/ 2 * t * t * t * t * t + b;\r\n            return c \/ 2*((t -= 2) * t * t * t * t + 2) + b;\r\n        }\r\n    },\r\n    Sine: {\r\n        easeIn: function(t, b, c, d) {\r\n            return -c * Math.cos(t\/d * (Math.PI\/2)) + c + b;\r\n        },\r\n        easeOut: function(t, b, c, d) {\r\n            return c * Math.sin(t\/d * (Math.PI\/2)) + b;\r\n        },\r\n        easeInOut: function(t, b, c, d) {\r\n            return -c \/ 2 * (Math.cos(Math.PI * t\/d) - 1) + b;\r\n        }\r\n    },\r\n    Expo: {\r\n        easeIn: function(t, b, c, d) {\r\n            return (t==0) ? b : c * Math.pow(2, 10 * (t\/d - 1)) + b;\r\n        },\r\n        easeOut: function(t, b, c, d) {\r\n            return (t==d) ? b + c : c * (-Math.pow(2, -10 * t\/d) + 1) + b;\r\n        },\r\n        easeInOut: function(t, b, c, d) {\r\n            if (t==0) return b;\r\n            if (t==d) return b+c;\r\n            if ((t \/= d \/ 2) < 1) return c \/ 2 * Math.pow(2, 10 * (t - 1)) + b;\r\n            return c \/ 2 * (-Math.pow(2, -10 * --t) + 2) + b;\r\n        }\r\n    },\r\n    Circ: {\r\n        easeIn: function(t, b, c, d) {\r\n            return -c * (Math.sqrt(1 - (t \/= d) * t) - 1) + b;\r\n        },\r\n        easeOut: function(t, b, c, d) {\r\n            return c * Math.sqrt(1 - (t = t\/d - 1) * t) + b;\r\n        },\r\n        easeInOut: function(t, b, c, d) {\r\n            if ((t \/= d \/ 2) < 1) return -c \/ 2 * (Math.sqrt(1 - t * t) - 1) + b;\r\n            return c \/ 2 * (Math.sqrt(1 - (t -= 2) * t) + 1) + b;\r\n        }\r\n    },\r\n    Elastic: {\r\n        easeIn: function(t, b, c, d, a, p) {\r\n            var s;\r\n            if (t==0) return b;\r\n            if ((t \/= d) == 1) return b + c;\r\n            if (typeof p == \"undefined\") p = d * .3;\r\n            if (!a || a < Math.abs(c)) {\r\n                s = p \/ 4;\r\n                a = c;\r\n            } else {\r\n                s = p \/ (2 * Math.PI) * Math.asin(c \/ a);\r\n            }\r\n            return -(a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) \/ p)) + b;\r\n        },\r\n        easeOut: function(t, b, c, d, a, p) {\r\n            var s;\r\n            if (t==0) return b;\r\n            if ((t \/= d) == 1) return b + c;\r\n            if (typeof p == \"undefined\") p = d * .3;\r\n            if (!a || a < Math.abs(c)) {\r\n                a = c; \r\n                s = p \/ 4;\r\n            } else {\r\n                s = p\/(2*Math.PI) * Math.asin(c\/a);\r\n            }\r\n            return (a * Math.pow(2, -10 * t) * Math.sin((t * d - s) * (2 * Math.PI) \/ p) + c + b);\r\n        },\r\n        easeInOut: function(t, b, c, d, a, p) {\r\n            var s;\r\n            if (t==0) return b;\r\n            if ((t \/= d \/ 2) == 2) return b+c;\r\n            if (typeof p == \"undefined\") p = d * (.3 * 1.5);\r\n            if (!a || a < Math.abs(c)) {\r\n                a = c; \r\n                s = p \/ 4;\r\n            } else {\r\n                s = p \/ (2  *Math.PI) * Math.asin(c \/ a);\r\n            }\r\n            if (t < 1) return -.5 * (a * Math.pow(2, 10* (t -=1 )) * Math.sin((t * d - s) * (2 * Math.PI) \/ p)) + b;\r\n            return a * Math.pow(2, -10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) \/ p ) * .5 + c + b;\r\n        }\r\n    },\r\n    Back: {\r\n        easeIn: function(t, b, c, d, s) {\r\n            if (typeof s == \"undefined\") s = 1.70158;\r\n            return c * (t \/= d) * t * ((s + 1) * t - s) + b;\r\n        },\r\n        easeOut: function(t, b, c, d, s) {\r\n            if (typeof s == \"undefined\") s = 1.70158;\r\n            return c * ((t = t\/d - 1) * t * ((s + 1) * t + s) + 1) + b;\r\n        },\r\n        easeInOut: function(t, b, c, d, s) {\r\n            if (typeof s == \"undefined\") s = 1.70158; \r\n            if ((t \/= d \/ 2) < 1) return c \/ 2 * (t * t * (((s *= (1.525)) + 1) * t - s)) + b;\r\n            return c \/ 2*((t -= 2) * t * (((s *= (1.525)) + 1) * t + s) + 2) + b;\r\n        }\r\n    },\r\n    Bounce: {\r\n        easeIn: function(t, b, c, d) {\r\n            return c - Tween.Bounce.easeOut(d-t, 0, c, d) + b;\r\n        },\r\n        easeOut: function(t, b, c, d) {\r\n            if ((t \/= d) < (1 \/ 2.75)) {\r\n                return c * (7.5625 * t * t) + b;\r\n            } else if (t < (2 \/ 2.75)) {\r\n                return c * (7.5625 * (t -= (1.5 \/ 2.75)) * t + .75) + b;\r\n            } else if (t < (2.5 \/ 2.75)) {\r\n                return c * (7.5625 * (t -= (2.25 \/ 2.75)) * t + .9375) + b;\r\n            } else {\r\n                return c * (7.5625 * (t -= (2.625 \/ 2.75)) * t + .984375) + b;\r\n            }\r\n        },\r\n        easeInOut: function(t, b, c, d) {\r\n            if (t < d \/ 2) {\r\n                return Tween.Bounce.easeIn(t * 2, 0, c, d) * .5 + b;\r\n            } else {\r\n                return Tween.Bounce.easeOut(t * 2 - d, 0, c, d) * .5 + c * .5 + b;\r\n            }\r\n        }\r\n    }\r\n}\r\nMath.tween = Tween;<\/pre>\n<\/div>\n<p>\u4e8e\u662f\uff0c\u501f\u52a9\u5927\u4eba\u6211<code>requestAnimationFrame<\/code>\u4ee5\u53ca\u4e0a\u9762\u7684\u52a8\u753b\u7b97\u6cd5\uff0c\u5404\u79cd\u52a8\u753b\u6548\u679c\u6240\u5411\u62ab\u9761\u4e86\uff0c\u54c8\u54c8\u54c8\u54c8\uff01\uff01<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/ww3.sinaimg.cn\/mw690\/4b4d632fgw1e94d3ohwnmj204603ga9y.jpg\" width=\"150\" height=\"124\" alt=\"\u4e0d\u9519\u54e6\uff0c\u56db\u57fa\u4f6c\u8868\u60c5\" class=\"alignnone\" \/><br \/>\n\u54c7\u54e6\u54c7\u54e6\uff0c\u5927\u8d5e\uff01\u53ef\u4e0d\u53ef\u4ee5\u7ed9\u6211\u4eec\u8fd9\u4e9b\u9f20\u8f88\u5f00\u5f00\u773c\u754c\uff1f<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/ww2.sinaimg.cn\/mw690\/4b4d632fgw1e94mzky6z8j202s02sq2s.jpg\" width=\"150\" height=\"150\" alt=\"\u4e86\u4e0d\u8d77 \u4e38\u5b50\" class=\"alignnone\" \/><br \/>\n\u660e\u5929\u653e\u5047\uff0c\u8001\u5a18\u5fc3\u60c5\u597d\uff0c\u5c31\u7ed9\u4f60\u4eec\u9732\u4e00\u624b\uff0c\u5b9e\u73b0\u4e2a\u94c1\u7403\u843d\u4e0b\u7684\u6548\u679c\u3002<\/p>\n<p>\u60a8\u53ef\u4ee5\u72e0\u72e0\u5730\u70b9\u51fb\u8fd9\u91cc\uff1a<a class=\"a_link\" target=\"_blank\" href=\"http:\/\/www.zhangxinxu.com\/study\/201309\/requestanimationframe-tween-easeoutbounce.html\">requestAnimationFrame+Tween\u7f13\u52a8\u5c0f\u7403\u843d\u5730\u6548\u679c<\/a><\/p>\n<p>\u622a\u56fe\u5982\u4e0b\uff1a<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"\/\/image.zhangxinxu.com\/image\/blog\/201309\/2013-09-30_185243.png\" width=\"478\" height=\"270\" alt=\"\u5c0f\u7403\u622a\u56fe \u5f20\u946b\u65ed-\u946b\u7a7a\u95f4-\u946b\u751f\u6d3b\" class=\"alignnone\" \/><\/p>\n<p>\u76f8\u5173\u6e90\u4ee3\u7801\u53ef\u4ee5\u53c2\u89c1demo\u9875\u9762\u6e90\u4ee3\u7801\u2014\u2014\u76f4\u63a5\u53f3\u952e\u5373\u53ef\u4ee5\u3002\u6838\u5fc3\u52a8\u753b\u90e8\u5206\u7684\u811a\u672c\u662f\uff1a<\/p>\n<div class=\"zxx_code\">\n<pre>funFall = function() {\r\n    var start = 0, during = 100;\r\n    var _run = function() {\r\n         start++;\r\n         var top = Tween.Bounce.easeOut(start, objBall.top, 500 - objBall.top, during);\r\n         ball.css(\"top\", top);\r\n         shadowWithBall(top);    <span style=\"color:green;\">\/\/ \u6295\u5f71\u8ddf\u968f\u5c0f\u7403\u7684\u52a8<\/span>\r\n         if (start < during) requestAnimationFrame(_run);\r\n    };\r\n    _run();\r\n};<\/pre>\n<\/div>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/ww1.sinaimg.cn\/mw690\/4b4d632fgw1e94q3ljs7dj204603gjra.jpg\" width=\"150\" height=\"124\" alt=\"\u592a\u68d2\u4e86 \u57fa\u4f6c\u4eec\" class=\"alignnone\" \/><br \/>\n\u6211\u9760\uff01\u592a\u52b2\u7206\u4e86\uff01\u592a\u5e26\u611f\u4e86\uff01\u4e38\u5b50\u6bbf\u4e0b\uff0c\u4f60\u592a\u725b\u903c\u5566\uff01\uff01<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/ww4.sinaimg.cn\/mw690\/4b4d632fgw1e94q5eyd7lj202o02r3yd.jpg\" width=\"150\" height=\"150\" alt=\"\u8036 \u5c0f\u4e38\u5b50\" class=\"alignnone\" \/><br \/>\n\u563b\u563b\uff0c\u5c0f\u610f\u601d\u5566\uff0c\u8bf8\u4f4d\uff01\u6700\u540e\uff0c\u9884\u795d\u5927\u5bb6\u8282\u65e5\u5feb\u4e50\uff01\uff01<\/p>\n<p><strong>\u8865\u5145\u4e8e2014-02-08<\/strong><br \/>\n\u65b0\u5e74\u4f0a\u59cb\uff0c\u6839\u636e<a href=\"http:\/\/blog.segmentfault.com\/humphry\/1190000000386368\">\u8fd9\u7bc7\u7ffb\u8bd1\u6587\u7ae0<\/a>\u4e00\u4e9b\u6d4b\u8bd5\u8bf4\u6cd5\uff0cFireFox\/Chrome\u6d4f\u89c8\u5668\u5bf9<code>setInterval<\/code>, <code>setTimeout<\/code>\u505a\u4e86\u4f18\u5316\uff0c\u9875\u9762\u5904\u4e8e\u95f2\u7f6e\u72b6\u6001\u7684\u65f6\u5019\uff0c\u5982\u679c\u5b9a\u65f6\u95f4\u9694\u5c0f\u4e8e<code>1<\/code>\u79d2\u949f(<code>1000ms<\/code>)\uff0c\u5219\u505c\u6b62\u4e86\u5b9a\u65f6\u5668\u3002\u4e0e<code>requestAnimationFrame<\/code>\u6709\u7c7b\u4f3c\u884c\u4e3a\u3002\u4f46\u5982\u679c\u65f6\u95f4\u95f4\u9694\u5927\u4e8e\u6216\u7b49\u4e8e<code>1000ms<\/code>\uff0c\u5b9a\u65f6\u5668\u4f9d\u7136\u6267\u884c\uff0c\u5373\u4f7f\u9875\u9762\u6700\u5c0f\u5316\u6216\u975e\u6fc0\u6d3b\u72b6\u6001\u3002<\/p>\n<p>\u53c2\u89c1\u4e0b\u8868\uff1a<\/p>\n<table class=\"params_table\"  cellpadding=\"0\" cellspacing=\"1\">\n<tbody>\n<tr>\n<th><\/th>\n<th>setInterval<\/th>\n<th>requestAnimationFrame<\/th>\n<\/tr>\n<tr>\n<td>IE<\/td>\n<td>\u65e0\u5f71\u54cd<\/td>\n<td>\u6682\u505c<\/td>\n<\/tr>\n<tr>\n<td>Safari<\/td>\n<td>\u65e0\u5f71\u54cd<\/td>\n<td>\u6682\u505c<\/td>\n<\/tr>\n<tr>\n<td>Firefox<\/td>\n<td>&gt;=1s<\/td>\n<td>1s - 3s<\/td>\n<\/tr>\n<tr>\n<td>Chrome<\/td>\n<td>&gt;=1s<\/td>\n<td>\u6682\u505c<\/td>\n<\/tr>\n<tr>\n<td>Opera<\/td>\n<td>\u65e0\u5f71\u54cd<\/td>\n<td>\u6682\u505c<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>\u76f8\u5173\u94fe\u63a5<\/strong><\/p>\n<ul>\n<li>http:\/\/easings.net\/zh-cn<\/li>\n<li>http:\/\/www.jiawin.com\/requestanimationframe-animation-windmill\/<\/li>\n<li>http:\/\/msdn.microsoft.com\/zh-cn\/library\/ie\/hh920765(v=vs.85).aspx<\/li>\n<li>http:\/\/www.paulirish.com\/2011\/requestanimationframe-for-smart-animating\/<\/li>\n<li>http:\/\/caniuse.com\/#search=requestAnimationFrame<\/li>\n<li>https:\/\/github.com\/zhangxinxu\/Tween\/blob\/master\/tween.js<\/li>\n<li>http:\/\/www.cnblogs.com\/cloudgamer\/archive\/2009\/01\/06\/tween.html<\/li>\n<li>http:\/\/blog.segmentfault.com\/humphry\/1190000000386368<\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/image.zhangxinxu.com\/image\/emtion\/emoji\/1f603.svg\" width=\"20\" height=\"20\" align=\"absmiddle\"><\/p>\n<p>\u672c\u6587\u4e3a\u539f\u521b\u6587\u7ae0\uff0c\u8f6c\u8f7d\u8bf7\u6ce8\u660e\u6765\u81ea<a href=\"https:\/\/www.zhangxinxu.com\/\">\u5f20\u946b\u65ed-\u946b\u7a7a\u95f4-\u946b\u751f\u6d3b<\/a>[<a href=\"https:\/\/www.zhangxinxu.com\/\">https:\/\/www.zhangxinxu.com<\/a>]<br \/>\n\u672c\u6587\u5730\u5740\uff1a<a href=\"https:\/\/www.zhangxinxu.com\/wordpress\/?p=3695\">https:\/\/www.zhangxinxu.com\/wordpress\/?p=3695<\/a><\/p>\n<p>\uff08\u672c\u7bc7\u5b8c\uff09<\/p>\n","protected":false},"excerpt":{"rendered":"<p><a href=\"http:\/\/www.zhangxinxu.com\/wordpress\/?p=3695\" title=\"\u70b9\u51fb\u67e5\u770b\u672c\u6587\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201309\/requestAnimationFrame-tween.jpg\" class=\"imgpad mb10\" width=\"550\" height=\"170\" alt=\"requestAnimationFrame\u4e0e\u52a8\u753b\"><\/a><br \/>\n\u672c\u6587\u53ef\u8c13JS\u5b9e\u73b0\u52a8\u753b\u5fc5\u8bfb\u6587\u7ae0\u3002\u8bbe\u8ba1\u5b9e\u73b0\u3001\u6027\u80fd\u3001\u52a8\u753b\u7b97\u6cd5\uff0cCSS3\u76f8\u5173\u7b49\u4e00\u7cfb\u5217\u5185\u5bb9\u3002\u914d\u4ee5\u751f\u52a8\u7684\u5bf9\u8bdd\u4f53\uff0c\u4e8c\u6b21\u5143\u4e0e\u4e09\u6b21\u5143\u7684\u78b0\u649e\uff1b\u4e30\u5bcc\u7684demo\u3001\u622a\u56fe\u4ee5\u53ca\u6e90\u4ee3\u7801\u5c55\u793a\uff0c\u5e73\u767d\u6613\u61c2\u7684\u6587\u5b57\uff0c\u76f8\u4fe1\u672c\u6587\u7684\u5185\u5bb9\u4e00\u5b9a\u80fd\u591f\u5bf9\u60a8\u7684\u5b66\u4e60\u6709\u6240\u5e2e\u52a9\uff01<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[71,867,204,121,868,322,129],"_links":{"self":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts\/3695"}],"collection":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/comments?post=3695"}],"version-history":[{"count":0,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts\/3695\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/media?parent=3695"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/categories?post=3695"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/tags?post=3695"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}