html5基于canvas制作酷炫,应用HTML5 Canvas制作酷炫科技背景动画特效
更多特效代码请添加HTML5前端交流群111645711
看这性感的线条,激情的律动!
废话不多说,上代码!
源代码
需要文档版本源码,可以加我的HTML5前端交流群111645711
* {
margin:0;
padding:0;
}
body {
font-size:16px;
font:400 16px/1.62 Georgia,"Xin Gothic","Hiragino Sans GB","Droid Sans Fallback","Microsoft YaHei",sans-serif;font-family: "PT serif",微軟正黑體,微软雅黑,华文细黑,Microsoft Yahei,Hiragino Sans GB,sans-serif;
color:#D0CCCC;
overflow:hidden;
text-shadow: 0px 0px 1px rgba(24, 22, 22, 0.35);
background-color: #000;
}
var canvas,
ctx,
width,
height,
size,
lines,
tick;
function line() {
this.path = [];
this.speed = rand(10, 20);
this.count = randInt(10, 30);
this.x = width / 2, +1;
this.y = height / 2 + 1;
this.target = {
x: width / 2,
y: height / 2
};
this.dist = 0;
this.angle = 0;
this.hue = tick / 5;
this.life = 1;
this.updateAngle();
this.updateDist();
}
line.prototype.step = function(i) {
this.x += Math.cos(this.angle) * this.speed;
this.y += Math.sin(this.angle) * this.speed;
this.updateDist();
if (this.dist < this.speed) {
this.x = this.target.x;
this.y = this.target.y;
this.changeTarget();
}
this.path.push({
x: this.x,
y: this.y
});
if (this.path.length > this.count) {
this.path.shift();
}
this.life -= 0.001;
if (this.life <= 0) {
this.path = null;
lines.splice(i, 1);
}
};
line.prototype.updateDist = function() {
var dx = this.target.x - this.x,
dy = this.target.y - this.y;
this.dist = Math.sqrt(dx * dx + dy * dy);
}
line.prototype.updateAngle = function() {
var dx = this.target.x - this.x,
dy = this.target.y - this.y;
this.angle = Math.atan2(dy, dx);
}
line.prototype.changeTarget = function() {
var randStart = randInt(0, 3);
switch (randStart) {
case 0: // up
this.target.y = this.y - size;
break;
case 1: // right
this.target.x = this.x + size;
break;
case 2: // down
this.target.y = this.y + size;
break;
case 3: // left
this.target.x = this.x - size;
}
this.updateAngle();
};
line.prototype.draw = function(i) {
ctx.beginPath();
var rando = rand(0, 10);
for (var j = 0, length = this.path.length; j < length; j++) {
ctx[(j === 0) ? "moveTo" : "lineTo"](this.path[j].x + rand(-rando, rando), this.path[j].y + rand(-rando, rando));
}
ctx.strokeStyle = "hsla(" + rand(this.hue, this.hue + 30) + ", 80%, 55%, " + (this.life / 3) + ")";
ctx.lineWidth = rand(0.1, 2);
ctx.stroke();
};
function rand(min, max) {
return Math.random() * (max - min) + min;
}
function randInt(min, max) {
return Math.floor(min + Math.random() * (max - min + 1));
};
function init() {
canvas = document.getElementById("canvas");
ctx = canvas.getContext("2d");
size = 30;
lines = [];
reset();
loop();
}
function reset() {
width = Math.ceil(window.innerWidth / 2) * 2;
height = Math.ceil(window.innerHeight / 2) * 2;
tick = 0;
lines.length = 0;
canvas.width = width;
canvas.height = height;
}
function create() {
if (tick % 10 === 0) {
lines.push(new line());
}
}
function step() {
var i = lines.length;
while (i--) {
lines[i].step(i);
}
}
function clear() {
ctx.globalCompositeOperation = "destination-out";
ctx.fillStyle = "hsla(0, 0%, 0%, 0.1";
ctx.fillRect(0, 0, width, height);
ctx.globalCompositeOperation = "lighter";
}
function draw() {
ctx.save();
ctx.translate(width / 2, height / 2);
ctx.rotate(tick * 0.001);
var scale = 0.8 + Math.cos(tick * 0.02) * 0.2;
ctx.scale(scale, scale);
ctx.translate(-width / 2, -height / 2);
var i = lines.length;
while (i--) {
lines[i].draw(i);
}
ctx.restore();
}
function loop() {
requestAnimationFrame(loop);
create();
step();
clear();
draw();
tick++;
}
function onresize() {
reset();
}
window.addEventListener("resize", onresize);
init();
适用浏览器:360、FireFox、Chrome、Opera、傲游、搜狗、世界之窗. 不支持Safari、IE8及以下浏览器。
来源:素材
html5基于canvas制作酷炫,应用HTML5 Canvas制作酷炫科技背景动画特效相关推荐
- 情人节程序员用HTML网页表白【彩色酷炫的空间背景动画特效】 HTML5七夕情人节表白网页源码 HTML+CSS+JavaScript
这是程序员表白系列中的100款网站表白之一,旨在让任何人都能使用并创建自己的表白网站给心爱的人看. 此波共有100个表白网站,可以任意修改和使用,很多人会希望向心爱的男孩女孩告白,生性腼腆的人即使那个 ...
- html5+css3满天星星音乐背景动画特效(超炫酷)
css3满天星星音乐背景动画特效 css3属性绘制唯美的满天星星和audio MP3音乐结合背景动画特效. 作品介绍 1.网页作品简介方面 :css3属性绘制唯美的满天星星和audio MP3音乐结合 ...
- php插入html动态背景,HTML5超酷响应式视频背景动画特效
简要教程 这是一款HTML5超酷响应式视频背景动画特效.该视频背景可以将视频自适应屏幕的大小,制作出炫酷的动态视频背景效果. 使用方法 在页面中引入bideo.js文件. HTML结构 该视频背景动画 ...
- android气球上升的属性动画,html5 canvas告白气球上升背景动画特效
特效描述:html5 canvas 告白气球上升 背景动画特效.html5基于canvas绘制各种卡通气球上升动画.告白气球背景动画特效. 代码结构 1. 引入JS 2. HTML代码 Balloon ...
- html画星空,html5 canvas绘制全屏的星空背景动画特效
特效描述:html5 canvas绘制 全屏星空背景 动画特效.html5 canvas背景动画,星空动画.连线区域跟随鼠标移动,外加碰壁检测 代码结构 1. 引入JS 2. HTML代码 var m ...
- 粒子背景php,html5+canvas圆形粒子移动背景动画特效
html5+canvas圆形粒子移动背景动画特效 this.update = function () { var lastPoint = { x: _this.x, y: _this.y }; // ...
- html5钻石,html5 canvas发光的钻石背景动画特效
特效描述:html5canvas 发光的钻石 背景动画特效.html5 canvas three.js绘制闪烁的钻石背景动画,跟随鼠标移动改变形状效果. 代码结构 1. 引入JS 2. HTML代码 ...
- HTML粒子碰撞烟花,html5 canvas漂亮的粒子烟花背景动画特效
特效描述:html5 canvas 漂亮的粒子烟花 背景动画特效.html5 canvas漂亮的粒子烟花背景动画特效 代码结构 1. HTML代码 class Vector2 { constructo ...
- html5 特效 背景 腾讯,html5腾讯QQ登录界面背景动画特效
特效描述:html5 腾讯QQ 登录界面 背景动画特效.腾讯QQ登陆界面动态背景,直接从腾讯网站获取,js代码有加密,做了个简单地示例 代码结构 1. 引入JS 2. HTML代码 *{margin: ...
最新文章
- 冲刺第三天 1.3 THU
- UVa 11107 (后缀数组 二分) Life Forms
- Eclipse安装 Activiti Designer插件
- 外观模式(Facade) - 为系统分层次
- 通过调用API函数实现的无边框窗体的拖拽,比判断坐标更快捷
- HDU - 6704 K-th occurrence (后缀数组+主席树)
- TreeView,TreeNode,TreeNodeCollection 的使用
- 专升本c语言名词解释题_福建普通高校专升本各类别考试题型及分值
- 2010.11.18 关于向窗口发送消息
- Linux搭建Elasticsearch集群
- 数据库学习--数据库基本概念
- kpi绩效考核流程图_绩效考核流程图
- highcharts去水印方法
- 淘客必看的抖音引流方案,淘客小白如何在抖音上引流?
- CSS系列之浮动详解
- [JZOJ5629]【NOI2018模拟4.4】Map
- 莎士比亚统计最高的词频数 java,spark,rdd
- html5网页制作拓扑,基于HTML5的网络拓扑图设计
- 渔业公司宣传片制作技巧
- 单片机24秒倒计时c语言,单片机汇编语言24秒倒计时程序