Coder Social home page Coder Social logo

css3-animation-to-gif's Introduction

css3-animation-to-gif

利用 Phantomjs 把 css3 动画 变成 gif 的帧

说明

一开始

  1. 使用 PhantomJS 抓取 demo 文件夹里 p-loading.htm 播放css3动画的截图
  2. 一张一张存储起来,放到 bubble-frame 里面
  3. 利用 gif 制作软件(我这里使用的是 Easy GIF Animator 6 Pro,一键操作,10秒不到)生成 gif 图(就是在 bubble-frame 里面的 bubble.gif)

gif 效果很差! 😱 🔫

所以修改

  1. 每次截图,保存为base64,先存储起来
  2. 新建一个带有 canvas 的页面,把存起来的图片,顺序平铺到画布上
  3. 再截这个 “sprite” 图片

使用 setInterval(或 setTimeout)播放这个图片: Demo

可以和 css3 的动画 做个对比,效果还不错~
或者看 这里

补充

  1. 最后生成的精灵图片,可以使用我写的 tiny node插件,自动压一下。当然也可以自己通过tiny官网去压一下,能节省不少空间
  2. page.evaluate 环境好像不能读取本地的图片,所以才改为base64的,如果有知道的童鞋希望可以告诉我一下
  3. 显示时,动画运行;隐藏时,动画停止。这样可以节省性能,也应该这样去做。聪明的你,一定知道怎么做~~

css3-animation-to-gif's People

Contributors

paper avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Forkers

zhangqm666

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.