官網地址:http://www.hatchpet.com/ 視頻需翻牆。
var scale = 1; var baseHeight = 544 * scale; var baseWidth = 602 * scale; var eachFrame = 15; var canvas = $('<canvas id="canvas"/>').css({ 'position': 'fixed', 'zIndex': 9999, 'bottom': '0', 'overflow': 'hidden', }).attr({ 'width': baseWidth, 'height': baseHeight, }); $('body').append(canvas); var frameCnt = 0; var context = canvas[0].getContext('2d'); function animate(isReset) { if (isReset) { frameCnt = 0; }; // clear context.clearRect(0, 0, baseWidth, baseHeight); // draw stuff context.drawImage(imageObjs[parseInt(frameCnt / eachFrame)], (frameCnt % eachFrame) * baseWidth, 0, baseWidth, baseHeight, 0, 0, baseWidth, baseHeight); frameCnt++; // request new frame if (frameCnt < eachFrame * 2) { setTimeout(animate, 1000 / 8); } else { animate(true); } } var pic = [ 'http://p1.zhimg.com/8c/fb/8cfbc0eb11019584c7ee0dccd4c8bf66_r.jpg', 'http://p1.zhimg.com/4f/3d/4f3db206b0fd094ef2fc00ece876ad30_r.jpg' ]; function preLoadImages(imgSrcList, callback) { var imageObjs = []; var len = imgSrcList.length; var callbackAfter = len; var preloadInterval = window.setInterval(function() { if (callbackAfter === 0) { window.clearInterval(preloadInterval); callback(); } }, 100); for (var i = 0; i < len; i++) { imageObjs[i] = new Image(); imageObjs[i].onload = function() { callbackAfter--; }; imageObjs[i].src = imgSrcList[i]; }; return imageObjs; } var imageObjs = preLoadImages(pic, function() { animate(true); });
var licksprite;var showingSprite=false;var playState;var playerReady=false;var shouldStart=false;var spriteTime=50.08;…
我对 js 只是非常一知半解,不过那个 spriteTime = 50.08 让人猜想,应该是检测在视频播放50.08秒后,触发网页上的 CSS sprite 动画。