ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

博客园页脚html代码,博客园页脚动态背景代码

2021-11-04 19:31:56  阅读:167  来源: 互联网

标签:canvas random dist 页脚 博客园 script window context 代码


Title

!function() {//封装方法,压缩之后减少文件大小

functionget_attribute(node, attr, default_value) {returnnode.getAttribute(attr)||default_value;

}//封装方法,压缩之后减少文件大小

functionget_by_tagname(name) {returndocument.getElementsByTagName(name);

}//获取配置参数

functionget_config_option() {varscripts=get_by_tagname("script"),

script_len=scripts.length,

script=scripts[script_len- 1];//当前加载的script

return{

l: script_len,//长度,用于生成id用

z: get_attribute(script,"zIndex",-1),//z-index

o: get_attribute(script,"opacity",0.8),//opacity

c: get_attribute(script,"color","255,255,255"),//color

n: get_attribute(script,"count",350)//count

};

}//设置canvas的高宽

functionset_canvas_size() {

canvas_width=the_canvas.width=window.innerWidth||document.documentElement.clientWidth||document.body.clientWidth,

canvas_height=the_canvas.height=window.innerHeight||document.documentElement.clientHeight||document.body.clientHeight;

}//绘制过程

functiondraw_canvas() {

context.clearRect(0,0, canvas_width, canvas_height);//随机的线条和当前位置联合数组

vare, i, d, x_dist, y_dist, dist;//临时节点

//遍历处理每一个点

random_points.forEach(function(r, idx) {

r.x+=r.xa,

r.y+=r.ya,//移动

r.xa*=r.x>canvas_width||r.x< 0 ? -1:1,

r.ya*=r.y>canvas_height||r.y< 0 ? -1:1,//碰到边界,反向反弹

context.fillRect(r.x- 0.5, r.y- 0.5,1,1);//绘制一个宽高为1的点

//从下一个点开始

for(i=idx+ 1; i

e=all_array[i];//当前点存在

if(null !==e.x&& null !==e.y) {

x_dist=r.x-e.x;//x轴距离 l

y_dist=r.y-e.y;//y轴距离 n

dist=x_dist*x_dist+y_dist*y_dist;//总距离, m

dist=e.max/ 2 &&(r.x-= 0.03 *x_dist, r.y-= 0.03 *y_dist),//靠近的时候加速

d=(e.max-dist)/e.max,

context.beginPath(),

context.lineWidth=d/ 2,

context.strokeStyle= "#555555",//这里是线条的颜色

context.moveTo(r.x, r.y),

context.lineTo(e.x, e.y),

context.stroke());

}

}

}), frame_func(draw_canvas);

}//创建画布,并添加到body中

varthe_canvas=document.createElement("canvas"),//画布

config=get_config_option(),//配置

canvas_id= "c_n" +config.l,//canvas id

context=the_canvas.getContext("2d"), canvas_width, canvas_height,

frame_func=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame|| function(func) {

window.setTimeout(func,1000 / 40);

}, random=Math.random,

current_point={

x:null,//当前鼠标x

y:null,//当前鼠标y

max:20000 //圈半径的平方

},

all_array;

the_canvas.id=canvas_id;

the_canvas.style.cssText= "position:fixed;top:0;left:0;z-index:" +config.z+ ";opacity:" +config.o;

get_by_tagname("body")[0].appendChild(the_canvas);//初始化画布大小

set_canvas_size();

window.οnresize=set_canvas_size;//当时鼠标位置存储,离开的时候,释放当前位置信息

window.οnmοusemοve= function(e) {

e=e||window.event;

current_point.x=e.clientX;

current_point.y=e.clientY;

}, window.οnmοuseοut= function() {

current_point.x= null;

current_point.y= null;

};//随机生成config.n条线位置信息

for(varrandom_points=[], i= 0; config.n>i; i++) {varx=random()*canvas_width,//随机位置

y=random()*canvas_height,

xa= 2 *random()- 1,//随机运动方向

ya= 2 *random()- 1;//随机点

random_points.push({

x: x,

y: y,

xa: xa,

ya: ya,

max:6000 //沾附距离

});

}

all_array=random_points.concat([current_point]);//0.1秒后绘制

setTimeout(function() {

draw_canvas();

},100);

}();

标签:canvas,random,dist,页脚,博客园,script,window,context,代码
来源: https://www.cnblogs.com/aixuexi666888/p/15509836.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有