Heim >Web-Frontend >H5-Tutorial >David Lanham 新 iOS 遊戲 “Hatch” 的官網視頻中,最後小寵物從畫面跑進網頁的效果是如何實現的?
官網地址:http://www.hatchpet.com/ 視頻需翻牆。
<code class="language-text">var scale = 1;
var baseHeight = 544 * scale;
var baseWidth = 602 * scale;
var eachFrame = 15;
var canvas = $('<canvas id="canvas"></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 </code>
弱答。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 动画。