canvas 悬浮效果

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<canvas id="bubble"></canvas>
<script type="text/javascript">
var canvas = document.getElementById('bubble');
var w = window.innerWidth;
var h = window.innerHeight
canvas.width=w;
canvas.height=h;
window.onresize=function(){
w = window.innerWidth;
h = window.innerHeight
canvas.width=w;
canvas.height=h;
}
var canCon=canvas.getContext('2d');
// var y=100,x=100;
// setInterval(function(){
// canCon.clearRect(0,0,w,h);
// canCon.beginPath();
// canCon.fillStyle='red';
// canCon.arc(200,y++,100,0,Math.PI*2)
// canCon.fill();
// },1000/60); function random(min,max){
return Math.random()*(max-min)+min;
}
var colorArray = ['#e08031','#c7ceb2','#199475','#0b6e48','#044d22'];
function Bubble(){};
var bubble =new Bubble();
Bubble.prototype={//定义属性
init:function(){//所有泡泡的基本零件
this.x=random(0,w);//浏览器的最左边到最右边
this.y=random(0,h);//浏览器的最左边到最右边
this.r=random(0,2);//http://www.peise.net/颜色
this.color=colorArray[Math.floor(random(0,5))];
this.xr=random(-1,1);
this.yr=random(-1,1);
this.D=50;
},
draw:function(){
canCon.beginPath();
canCon.fillStyle=this.color;
canCon.arc(this.x,this.y,this.r,0,Math.PI*2)
canCon.fill();
},
update:function(){
this.x+=this.xr;
this.y+=this.yr;
if(this.x-this.r<0 || this.x+this.r>w){
this.xr = -this.xr;
}else if(this.y-this.r<0 || this.y+this.r>h){
this.yr = -this.yr;
}
this.xD= (positionX-this.x<0)?-(positionX-this.x):(positionX-this.x); //小球和鼠标的位置距离
this.yD= (positionY-this.y<0)?-(positionY-this.y):(positionY-this.y); //小球和鼠标的位置距离
if(this.xD<this.D&&this.yD<this.D){
this.r+=1;
if(this.r>100){this.r=100};
}else if(this.r>4&&this.xD>this.D&&this.yD>this.D){
this.r-=1;
}
this.draw();
}
} var bublleArray = [];
function create(){
var bubble =new Bubble();//shengcheng
bubble.init();//小泡泡的样子
bubble.draw();
bublleArray.push(bubble);//一出生就保存
}
for(var i=0;i<10000;i++){
create();
}
setInterval(function(){
canCon.clearRect(0,0,w,h);
for(var b of bublleArray){
b.update();
}
},1000/60);
var positionX,positionY;
canvas.onmousemove=function(){
var ev = ev || window.event;
positionX=ev.clientX;
positionY=ev.clientY;
positionX=ev.clientX;
}
//春函数就是只进行计算
</script>
</body>
</html>
canvas 悬浮效果的更多相关文章
- 使用Three.js实现神奇的3D文字悬浮效果
声明:本文涉及图文和模型素材仅用于个人学习.研究和欣赏,请勿二次修改.非法传播.转载.出版.商用.及进行其他获利行为. 背景 在 Three.js Journey 课程示例中,提供了一个使用 Thre ...
- CodePen 作品秀:Canvas 粒子效果文本动画
作品名称——Shape Shifter,基于 Canvas 的粒子图形变换实验.在页面下方的输入框输入文本,上面就会进行变换出对应的粒子效果文本动画. CodePen 作品秀系列向大家展示来自 Cod ...
- Android 仿美团网,大众点评购买框悬浮效果之修改版
转帖请注明本文出自xiaanming的博客(http://blog.csdn.net/xiaanming/article/details/17761431),请尊重他人的辛勤劳动成果,谢谢! 我之前写 ...
- 纯CSS实现的右侧底部简洁悬浮效果
我们见过很多页面右侧浮动效果,最早有QQ联系面板,对联广告等,大多数都是基于Javascript实现的动态效果,今天我给大家分享一个只需要CSS结合DIV实现的右侧浮动效果. HTML 我们希望悬浮效 ...
- HTML5 Canvas动画效果演示
HTML5 Canvas动画效果演示 主要思想: 首先要准备一张有连续帧的图片,然后利用HTML5 Canvas的draw方法在不同的时间 间隔绘制不同的帧,这样看起来就像动画在播放. 关键技术点: ...
- Android对ScrollView滚动监听,实现美团、大众点评的购买悬浮效果
转帖请注明本文出自xiaanming的博客(http://blog.csdn.net/xiaanming/article/details/17761431),请尊重他人的辛勤劳动成果,谢谢! 我之前写 ...
- HTML5 Canvas动画效果演示 - 流浪的鱼 - 博客频道 - CSDN.NET
HTML5 Canvas动画效果演示 - 流浪的鱼 - 博客频道 - CSDN.NET HTML5 Canvas动画效果演示
- HTML5 Canvas动画效果实现原理
在线演示 使用HTML5画布可以帮助我们高速实现简单的动画效果.基本原理例如以下: 每隔一定时间绘制图形而且清除图形,用来模拟出一个动画过程,能够使用context.clearRect(0, 0, x ...
- 如果去掉UITableView上的section的headerView和footerView的悬浮效果
项目需要cell的间距,又不需要悬浮效果,百度之后找到这个方法,记录一下,备忘. 用UIScrollView的代理方法实现 - (void)scrollViewDidScroll:(UIScrollV ...
随机推荐
- nginx显示静态html爆502 bad gateway的错误提示
在centos的服务器上,没有启动php-fcgi. 本来是想设置显示一个静态文件目录的,用不着php,于是就关闭了php-fcgi. 结果打开爆了一个大大的nginx502 bad gateway的 ...
- def跨域+jwt
1.跨域 由于浏览器具有“同源策略”的限制.如果在同一个域下发送ajax请求,浏览器的同源策略不会阻止.如果在不同域下发送ajax,浏览器的同源策略会阻止. 总结 域相同,永远不会存在跨域. crm, ...
- 纯django开发博客系统
企业级教程:纯django开发博客系统 1.视频教程 https://www.duanshuilu.com/ 2.教程文档 https://www.duanshuilu.com/ 0.课程简介1.简价 ...
- MySQL 统计行数的 count
MySQL count() 函数我们并不陌生,用来统计每张表的函数.但如果你的表越来越大,并且是 InnoDB 引擎的话,会发现计算的速度会越来越慢.在这篇文章里,会先介绍 count() 实现的原理 ...
- vue--基础应用 全选
1.用computed实现全选 <body> <div id="app"> <input type="checkbox" v-mo ...
- Array.isArray() 判断是不是数组
var arr = new Array(); if(Array.isArray()){ console.log('yes') } else { conssole.log('no') }
- 对时间进行操作 加减 XXX天
date:要操作的时间目标 days: 要加减的天数时间 addDate: function(date, days) { if (date == '') { return '' }; if (days ...
- [Visual Basic]冒泡排序及优化
冒泡排序 注意点 越界问题:i的边界是n-1,也就是说是对总共的第1~n个数进行排列(最后一个数处于被比较状态,不需要额外主动比较):j的初始值或最终值与当前i的值 有关题目中往往会改变i的值来考察, ...
- [Linux][C][gcc] Linux GCC 编译链接 报错ex: ./libxxx.so: undefined reference to `shm_open'
本人原创文章,文章是在此代码github/note的基础上进行补充,转载请注明出处:https://github.com/dramalife/note. 以librt丶用户自定义动态库libxxx 和 ...
- Natas8 Writeup(常见编码、php函数)
Natas8: 同样给了php源码,审计源码,发现给了一个预设参数encodedSecret,以及一个加密函数encodeSecret, 该函数将secret参数先进行base64编码.然后用strr ...