第一次搞动画有点慌,没用过 Canvas API,不知道一天内能不能搞出来。一开始是想用类似于 Google 在灭霸搜索结果页面加的彩蛋,点击无限手套就会触发灰飞烟灭效果,但仔细想了一下,直接照搬网上现成的动画的话会拉低用户对 Gitee 的评价,于是决定用其它效果。
碎片化
页面变成碎片的效果比较容易实现,大致思路是根据屏幕宽高计算 x 和 y 轴上的碎片数量,然后计算每个碎片的坐标,伪代码如下:
1 2 3 4 5 6 7 8
const size = 32;
for (let x = 0; x < Math.ceil(canvas.width / size); ++x) { for (let y = 0; x < Math.ceil(canvas.height / size); ++y) { // 四个参数对应 x, y, width, height new Piece(x * size, y * size, size, size) } }
对于第一个问题,原因是 page_specific_style_bundle_tag 方法输出的 link 标签的 media 属性默认值是 screen,这使得 link 标签引入的 css 代码仅在 screen 上有效。解决方法是手动将 media 属性设为 all,然后添加 @media print 查询,隐藏无关内容。
The reason we need default is that since webpack 4, when importing a CommonJS module, the import will no longer resolve to the value of module.exports, it will instead create an artificial namespace object for the CommonJS module. For more information on the reason behind this, read webpack 4: import() and CommonJs