8个经典炫酷的HTML5,一款基于HTML5

图片 6
永利皇宫402

实现的代码。

6、HTML5 Canvas实现画板涂鸦动画应用

记得之前我们分享过一款HTML5
Canvas画板工具,可以切换不同的笔刷,功能十分强大。本文今天要再来分享一款基于HTML5 Canvas的画板涂鸦动画应用,功能和之前那个类似,但是新增了回撤和清空画板的操作,实现思路也基本类似。

图片 1

在线演示        源码下载

<div class="wrap">          <canvas id="canvas" class="fl" width="600" height="400">          </canvas>          <div id="control" class="fl">              <div id="canvas-color">                  <h5>                      画笔颜色</h5>                  <ul>                      <li style="background: #fef4ac"></li>                      <li style="background: #0018ba"></li>                      <li style="background: #ffc200"></li>                      <li style="background: #f32f15"></li>                      <li style="background: #cccccc"></li>                      <li style="background: #5ab639"></li>                  </ul>              </div>              <div id="canvas-brush">                  <h5>                      画笔大小</h5>                                                  </div>              <div id="canvas-control">                  <h5>                      操作</h5>                                                  </div>              <div id="canvas-drawImage">                  <h5>                      生成图像</h5>                  <p>                      <button class="drawImage">                          生成图像</button></p>              </div>          </div>      </div>      <div id="imgDiv">      </div>

5、HTML5 Canvas炫酷的火焰风暴动画

利用HTML5技术,我们已经实现过不少关于火焰动画特效的HTML5应用,尤其是和Canvas搭配,比如HTML5动感的火焰燃烧动画特效和HTML5
Canvas火焰喷射动画效果。这次给大家带来的是一款基于HTML5
Canvas的火焰风暴动画特效,改动画效果就像从天上掉落火焰一样,火焰风暴逐渐蔓延到整一个画布。

图片 2

在线演示        源码下载

html代码:

2、HTML5 Canvas瀑布动画 超逼真

这次我们来分享一款很酷的HTML5 Canvas瀑布动画,瀑布动画非常逼真。整个瀑布动画像是从石头缝里流出来的溪水,然后沿着悬崖飞落下来,效果非常不错。

图片 3

在线演示        源码下载

 html, body, canvas, div, ul, li, h5, p          {              margin: 0;              padding: 0;              -moz-user-select: none;              -webkit-user-select: none;          }          img          {              border: 1px #ccc solid;          }          ul, li          {              list-style: none;          }          .wrap          {              width: 740px;              margin: 20px auto 5px;              border: 1px #ccc solid;              overflow: hidden;          }          .fl          {              float: left;              display: inline;          }          #canvas          {              border-right: 1px #ccc solid;              cursor: crosshair;          }          #control          {              width: 130px;              height: 400px;              margin-left: 4px;          }          #control div          {              padding: 5px;          }          #canvas-color ul          {              overflow: hidden;          }          #canvas-color ul li          {              float: left;              display: inherit;              width: 13px;              height: 13px;              border: 3px #fff solid;              margin: 8px;              cursor: pointer;          }          #canvas-color ul li.js-border-color          {              border-color: #000;          }          #canvas-brush span          {              display: inline-block;              width: 10px;              height: 10px;              margin-left: 10px;              background: url(images/brush.png);              cursor: pointer;          }          #canvas-brush span.small-brush          {              background-position: -6px -6px;          }          #canvas-brush span.middle-brush          {              background-position: -31px -6px;          }          #canvas-brush span.big-brush          {              background-position: -56px -6px;          }          #canvas-brush span.js-bg-color          {              background-color: #aaa;          }          #canvas-control span          {              display: inline-block;              width: 20px;              height: 15px;              margin-left: 10px;              background: url(images/sketchpad_icons.png);              cursor: pointer;          }          #canvas-control span.return-control          {              background-position: -2px -148px;          }          #canvas-control span.next-control          {              background-position: right -168px;          }          #canvas-control span.empty-control          {              background-position: -2px -188px;          }          #canvas-control span.js-return-control          {              background-position: -2px -209px;          }          #canvas-control span.js-next-control          {              background-position: right -230px;          }          #canvas-control span.js-empty-control          {              background-position: -2px -251px;          }          #imgDiv          {              text-align: center;          }

1、HTML5 Canvas可拖动的弹性大树摇摆动画

今天让我们继续来分享一个炫酷的HTML5动画,它是一款基于HTML5
Canvas的大树摇摆动画,这款HTML5动画的特点是我们可以拖拽树枝,从而让整棵树摇摆起来,这样就真实地模拟了大树从摇摆到静止的整个过程,相当逼真。

图片 4

在线演示        源码下载

  var doc = document,  canvas = doc.getElementById('canvas'),  colorDiv = doc.getElementById('canvas-color'),  brushDiv = doc.getElementById('canvas-brush'),  controlDiv = doc.getElementById('canvas-control'),  drawImageDiv = doc.getElementById('canvas-drawImage'),  imgDiv = doc.getElementById('imgDiv');          function Canvas() {              this.init.apply(this, arguments);          }          Canvas.prototype = {              //存储当前表面状态数组-上一步              preDrawAry: [],              //存储当前表面状态数组-下一步              nextDrawAry: [],              //中间数组              middleAry: [],              //配置参数              confing: {                  lineWidth: 1,                  lineColor: "blue",                  shadowBlur: 2              },              init: function (oCanvas, oColor, oBrush, oControl, oDrawImage, imgDiv) {                  this.canvas = oCanvas;                  this.context = oCanvas.getContext('2d');                  this.colorDiv = oColor;                  this.brushDiv = oBrush;                  this.controlDiv = oControl;                  this.drawImageDiv = oDrawImage;                  this.imgDiv = imgDiv;                  this._initDraw();                  this._draw(oCanvas);                  this.setColor();                  this.setBrush();                  this.preClick();                  this.nextClick();                  this.clearClick();                  this.drawImage(oCanvas);              },              _initDraw: function () {                  var preData = this.context.getImageData(0, 0, 600, 400);                  //空绘图表面进栈                  this.middleAry.push(preData);              },              //涂鸦主程序              _draw: function (oCanvas, context) {                  var _this = this;                  oCanvas.onmousedown = function (e) {                      var x = e.clientX,              y = e.clientY,              left = this.parentNode.offsetLeft,              top = this.parentNode.offsetTop,              canvasX = x - left,              canvasY = y - top;                      _this._setCanvasStyle();                      //清除子路径                      _this.context.beginPath();                      _this.context.moveTo(canvasX, canvasY);                      //当前绘图表面状态                      var preData = _this.context.getImageData(0, 0, 600, 400);                      //当前绘图表面进栈                      _this.preDrawAry.push(preData);                      document.onmousemove = function (e) {                          var x2 = e.clientX,                      y2 = e.clientY,                      t = e.target,                      canvasX2 = x2 - left,                      canvasY2 = y2 - top;                          if (t == oCanvas) {                              _this.context.lineTo(canvasX2, canvasY2);                              _this.context.stroke();                          } else {                              _this.context.beginPath();                          }                      }                      document.onmouseup = function (e) {                          var t = e.target;                          if (t == oCanvas) {                              //当前绘图表面状态                              var preData = _this.context.getImageData(0, 0, 600, 400);                              if (_this.nextDrawAry.length == 0) {                                  //当前绘图表面进栈                                  _this.middleAry.push(preData);                              } else {                                  _this.middleAry = [];                                  _this.middleAry = _this.middleAry.concat(_this.preDrawAry);                                  _this.middleAry.push(preData);                                  _this.nextDrawAry = [];                                  $('.js-next-control').addClass('next-control');                                  $('.next-control').removeClass('js-next-control');                              }                                _this._isDraw();                          }                          this.onmousemove = null;                      }                  }              },              //设置画笔              _setCanvasStyle: function () {                  this.context.lineWidth = this.confing.lineWidth;                  this.context.shadowBlur = this.confing.shadowBlur;                  this.context.shadowColor = this.confing.lineColor;                  this.context.strokeStyle = this.confing.lineColor;              },              //设置颜色              setColor: function () {                  this.colorDiv.onclick = this.bind(this, this._setColor);              },              _setColor: function (e) {                  var t = e.target;                  if (t.nodeName.toLowerCase() == "li") {                      this.confing.lineColor = t.style.backgroundColor;                      $('.js-border-color').removeClass('js-border-color');                      $(t).addClass('js-border-color');                  }              },              //设置画笔大小              setBrush: function () {                  this.brushDiv.onclick = this.bind(this, this._setBrush);              },              _setBrush: function (e) {                  var t = e.target;                  if (t.nodeName.toLowerCase() == "span") {                      if (t.className.indexOf("small-brush") >= 0) {                          this.confing.lineWidth = 3;                      } else if (t.className.indexOf("middle-brush") >= 0) {                          this.confing.lineWidth = 6;                      } else if (t.className.indexOf("big-brush") >= 0) {                          this.confing.lineWidth = 12;                      }                      $('.js-bg-color').removeClass('js-bg-color');                      $(t).addClass('js-bg-color');                  }              },              //判断是否已涂鸦,修改按钮状态              _isDraw: function () {                  if (this.preDrawAry.length) {                      $('.return-control').addClass('js-return-control');                      $('.return-control').removeClass('return-control');                      $('.empty-control').addClass('js-empty-control');                      $('.empty-control').removeClass('empty-control');                  } else {                      return false;                  }              },              //点击上一步-改变涂鸦当前状态              preClick: function () {                  var pre = this.controlDiv.getElementsByTagName("span")[0];                  pre.onclick = this.bind(this, this._preClick);              },              _preClick: function () {                  if (this.preDrawAry.length > 0) {                      var popData = this.preDrawAry.pop();                      var midData = this.middleAry[this.preDrawAry.length + 1];                      this.nextDrawAry.push(midData);                      this.context.putImageData(popData, 0, 0);                  }                  if (this.nextDrawAry.length) {                      $('.next-control').addClass('js-next-control');                      $('.next-control').removeClass('next-control');                  }                  if (this.preDrawAry.length == 0) {                      $('.js-return-control').addClass('return-control');                      $('.return-control').removeClass('js-return-control');                  }              },              //点击下一步-改变涂鸦当前状态              nextClick: function () {                  var next = this.controlDiv.getElementsByTagName("span")[1];                  next.onclick = this.bind(this, this._nextClick);              },              _nextClick: function () {                  if (this.nextDrawAry.length) {                      var popData = this.nextDrawAry.pop();                      var midData = this.middleAry[this.middleAry.length - this.nextDrawAry.length - 2];                      this.preDrawAry.push(midData);                      this.context.putImageData(popData, 0, 0);                  }                  if (this.preDrawAry.length) {                      $('.return-control').addClass('js-return-control');                      $('.return-control').removeClass('return-control');                  }                    if (this.nextDrawAry.length == 0) {                      $('.js-next-control').addClass('next-control');                      $('.next-control').removeClass('js-next-control');                  }              },              //清空              clearClick: function () {                  var clear = this.controlDiv.getElementsByTagName("span")[2];                  clear.onclick = this.bind(this, this._clearClick);              },              _clearClick: function () {                  var data = this.middleAry[0];                  this.context.clearRect(0, 0, this.context.canvas.width, this.context.canvas.height);                  this.preDrawAry = [];                  this.nextDrawAry = [];                  this.middleAry = [this.middleAry[0]];                  this.controlDiv.getElementsByTagName("span")[0].className = "return-control";                  this.controlDiv.getElementsByTagName("span")[1].className = "next-control";                  this.controlDiv.getElementsByTagName("span")[2].className = "empty-control";              },              //生成图像              drawImage: function () {                  var btn = this.drawImageDiv.getElementsByTagName("button")[0];                  btn.onclick = this.bind(this, this._drawImage);              },              _drawImage: function () {                  var url = this.canvas.toDataURL('image/png'),               img = new Image();                  img.src = url;                  this.imgDiv.innerHTML = "";                  this.imgDiv.appendChild(img);              },              bind: function (obj, handler) {                  return function () {                      return handler.apply(obj, arguments);                  }              }          }          new Canvas(canvas, colorDiv, brushDiv, controlDiv, drawImageDiv, imgDiv);

3、HTML5统计图表数据初始动画

之前我们已经向大家分享很多HTML5图表了,比如这款HTML5
Canvas折线图表和柱形图表就比较经典。今天要介绍的也是一款HTML5图表,该统计图表的特点是图表数据在初始化的时候会出现很酷的动画特效,特别是环形百分比应用还会出现百分比数的动态更新。

图片 5

在线演示        源码下载

图片 6

4、HTML5 Canvas图片马赛克模糊动画

经常可以在网上或者电视上看到被马赛克模糊的图片或者视频,今天我们要利用HTML5 Canvas技术来实现图片的马赛克模糊效果。在演示中我们可以拖动滑竿来设置马赛克模糊的程度,你可以在不同的值下观察图片被马赛克后的效果。HTML5的确非常强大。

图片 7

在线演示        源码下载

在线预览   源码下载

8个经典炫酷的HTML5 Canvas动画欣赏,

HTML5非常强大,尤其是Canvas技术的应用,让HTML5几乎可以完成所有Flash能完成的效果。本文精选了8个经典炫酷的HTML5
Canvas动画欣赏,每一个都提供全部的源代码,希望对你有所帮助。


8、HTML5 Canvas放射线动画

这是一款基于HTML5 Canvas的放射线动画,实现这款动画的思路也比较简单,先是根据数学图形公式构造放射线绘制的路径,然后利用HTML5将射线绘制在Canvas上,并在射线上绘制随机的颜色,这样整个射线图形看上去色彩斑斓。

图片 8

在线演示        源码下载

以上就是8个经典炫酷的HTML5 Canvas动画,你喜欢吗?欢迎给我意见。

Canvas动画欣赏,
HTML5非常强大,尤其是Canvas技术的应用,让HTML5几乎可以完成所有Flash能完成的效果。本文精选了8个经典…

今天给各网友分享一款基于HTML5
Canvas的画板涂鸦动画。记得之前我们分享过一款HTML5
Canvas画板工具,可以切换不同的笔刷,功能十分强大。本文今天要再来分享一款基于HTML5
Canvas的画板涂鸦动画应用,功能和之前那个类似,但是新增了回撤和清空画板的操作,实现思路也基本类似。实现的效果图如下:

7、HTML5动感的火焰燃烧动画特效

这又是一款基于HTML5的超炫动画特效,是一款动感的火焰燃烧动画效果。这款HTML5动画火焰燃烧非常逼真,之前我们也分享过一些其他的HTML5火焰燃烧动画,比如:HTML5
Canvas火焰燃烧动画和纯CSS3实现打火机火焰动画。一般像这样的HTML5动画都是基于Canvas的,今天的这款也不例外。

图片 9

在线演示        源码下载

css代码:

js代码:

via:

发表评论

电子邮件地址不会被公开。 必填项已用*标注

网站地图xml地图