javascript - 谷歌涂鸦是如何工作的?

标签 javascript html canvas google-doodle

Google 涂鸦如何工作?

当我搜索它时,我发现了以下内容

  1. Gif 动画
  2. 动画 Jpeg 帧。 Sprite 图像将包含所有帧,并且该帧使用 JavaScript 进行动画处理。
  3. Canvas

哪一个是正确的?

最佳答案

首先,他们附上 <img>将 JPEG 标记为 <div> 内的所有动画帧标签的固定高度为 182 像素,并且 overflow hidden 。可以说,这创建了一个固定窗口,它屏蔽了除当前动画帧之外的所有内容。该图像使用 JavaScript 进行动画处理,这会更改 top绝对定位图像的属性,将其向上滑动固定间隔 setTimeout()功能。

以下是 Google 的一些示例代码,摘自引用资料:

<div style="height:182px;position:relative;width:468px;overflow:hidden">
    <img border="0" src="source.jpg" id="filmstrip" style="position: absolute; height: 2912px; top: -0px; display: block; ">
</div>

Jquery:

<script>

function naiveAnimation(id) {

    var img = document.getElementById(id);
    var offset = 0;
    var animate = function() {
        //slide the image correct frame of animation given by  offset
        img.style.top = -offset + "px";
        //calculate offset to next frame
        offset = Math.floor(offset + 182);
        //if we are not yet on the last frame...
        if(offset < 2912) {
            //call me again in half a second
            window.setTimeout(animate, 500);
        } else {
            //at last frame, so all done!
        }
    };
    //start the animation
    animate();
}

naiveAnimation('filmstrip');

</script>

关于javascript - 谷歌涂鸦是如何工作的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24177651/

相关文章:

canvas - 在 <canvas> 上渲染 MathJax 输出

javascript - 如何推迟Paperjs中光栅的渲染?

javascript - Jest - 调用模拟函数不计算在内

javascript - ISO8601 日期格式中两个日期之间的天数

html - 输入按钮图像在提交时消失

javascript - 鼠标离开时取消悬停 Action

javascript - 从数组中过滤数据

javascript findIndex 与 IE 的问题

php - 使用 POST 方法在 2 个 php 之间传递变量

javascript - Canvas HTML5 数据点到数组