博客园特效——点击出现爱心❥,实现代码:JavaScript

<script type="text/javascript">
(function(window,document,undefined){var hearts = [];window.requestAnimationFrame = (function(){return window.requestAnimationFrame || window.webkitRequestAnimationFrame ||window.mozRequestAnimationFrame ||window.oRequestAnimationFrame ||window.msRequestAnimationFrame ||function (callback){setTimeout(callback,1000/60);}})();init();function init(){css(".heart{width: 10px;height: 10px;position: fixed;background: #f00;transform: rotate(45deg);-webkit-transform: rotate(45deg);-moz-transform: rotate(45deg);}.heart:after,.heart:before{content: '';width: inherit;height: inherit;background: inherit;border-radius: 50%;-webkit-border-radius: 50%;-moz-border-radius: 50%;position: absolute;}.heart:after{top: -5px;}.heart:before{left: -5px;}");attachEvent();gameloop();}function gameloop(){for(var i=0;i<hearts.length;i++){if(hearts[i].alpha <=0){document.body.removeChild(hearts[i].el);hearts.splice(i,1);continue;}hearts[i].y--;hearts[i].scale += 0.004;hearts[i].alpha -= 0.013;hearts[i].el.style.cssText = "left:"+hearts[i].x+"px;top:"+hearts[i].y+"px;opacity:"+hearts[i].alpha+";transform:scale("+hearts[i].scale+","+hearts[i].scale+") rotate(45deg);background:"+hearts[i].color;}requestAnimationFrame(gameloop);}function attachEvent(){var old = typeof window.onclick==="function" && window.onclick;window.onclick = function(event){old && old();createHeart(event);}}function createHeart(event){var d = document.createElement("div");d.className = "heart";hearts.push({el : d,x : event.clientX - 5,y : event.clientY - 5,scale : 1,alpha : 1,color : randomColor()});document.body.appendChild(d);}function css(css){var style = document.createElement("style");style.type="text/css";try{style.appendChild(document.createTextNode(css));}catch(ex){style.styleSheet.cssText = css;}document.getElementsByTagName('head')[0].appendChild(style);}function randomColor(){return "rgb("+(~~(Math.random()*255))+","+(~~(Math.random()*255))+","+(~~(Math.random()*255))+")";}
})(window,document);
</script>

博客园背景特效——背景出现蜘蛛网特效,实现代码:JavaScript

<script>
! function() {//封装方法,压缩之后减少文件大小function get_attribute(node, attr, default_value) {return node.getAttribute(attr) || default_value;}//封装方法,压缩之后减少文件大小function get_by_tagname(name) {return document.getElementsByTagName(name);}//获取配置参数function get_config_option() {var scripts = get_by_tagname("script"),script_len = scripts.length,script = scripts[script_len - 1]; //当前加载的scriptreturn {l: script_len, //长度,用于生成id用z: get_attribute(script, "zIndex", -1), //z-indexo: get_attribute(script, "opacity", 0.5), //opacityc: get_attribute(script, "color", "0,0,0"), //colorn: get_attribute(script, "count", 99) //count};}//设置canvas的高宽function set_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;}//绘制过程function draw_canvas() {context.clearRect(0, 0, canvas_width, canvas_height);//随机的线条和当前位置联合数组var e, i, d, x_dist, y_dist, dist; //临时节点//遍历处理每一个点random_lines.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 < all_array.length; i++) {e = all_array[i];//不是当前点if (null !== e.x && null !== e.y) {x_dist = r.x - e.x, //x轴距离 ly_dist = r.y - e.y, //y轴距离 ndist = x_dist * x_dist + y_dist * y_dist; //总距离, mdist < e.max && (e === current_point && 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 = "rgba(" + config.c + "," + (d + 0.2) + ")",context.moveTo(r.x, r.y),context.lineTo(e.x, e.y),context.stroke());}}}), frame_func(draw_canvas);}//创建画布,并添加到body中var the_canvas = document.createElement("canvas"), //画布config = get_config_option(), //配置canvas_id = "c_n" + config.l, //canvas idcontext = 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 / 45);}, random = Math.random,current_point = {x: null, //当前鼠标xy: null, //当前鼠标ymax: 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.onresize = set_canvas_size;//当时鼠标位置存储,离开的时候,释放当前位置信息window.onmousemove = function(e) {e = e || window.event, current_point.x = e.clientX, current_point.y = e.clientY;}, window.onmouseout = function() {current_point.x = null, current_point.y = null;};//随机生成config.n条线位置信息for (var random_lines = [], i = 0; config.n > i; i++) {var x = random() * canvas_width, //随机位置y = random() * canvas_height,xa = 2 * random() - 1, //随机运动方向ya = 2 * random() - 1;random_lines.push({x: x,y: y,xa: xa,ya: ya,max: 12000 //沾附距离});}all_array = random_lines.concat([current_point]);//0.1秒后绘制setTimeout(function() {draw_canvas();}, 100);
}();
</script>

博客园背景特效之《爱心+蜘蛛网》相关推荐

  1. 博客园背景特效(粒子线条,彩带,滴墨水)

    博客园动态背景 博客园许多个人博客首页里面的背景加入了特效 以下展示几个好玩的特效 一.动态粒子线条.带鼠标吸附 <!DOCTYPE html> <html lang="e ...

  2. 屏蔽博客园背景动态线条

    1. 问题描述 由于博客园允许用户添加含js的html代码来装饰自己的博客界面,这导致很多人跟风地给自己博客添加背景动态线条.live2D等,其中动态背景线条如下图所示: 它不停地随机生成线条,并漂浮 ...

  3. 博客园背景滴墨水特效

    设计自己的神奇滴墨水,你只需这几步: 点开博客园后台 点开设置 找到"页首 HTML 代码"(页尾也可以) 输入代码保存即可 (要先申请js权限哦) 代码如下: <!DOCT ...

  4. 博客园背景设置CSS代码

    /配色参考->>->>>//https://zh.spycolor.com/color-index,a*/ #home { margin: 0 auto; width: ...

  5. DIY修改博客园背景用【保存图片用】

    在火狐浏览器下F12进入样式,根据右侧栏的css代码,把需要修改的修改了,然后立即就能看见效果.将代码复制到后台设置那里的css样式里就好了. 以下是我用来保存图片网址的工具...自己用的,如果紧紧想 ...

  6. 个人博客园样式、背景及细节美化过程

    主页美化: 主要参考嘻哈烧饼的美化,在TA的基础上增加了对主页背景.色调以及侧边栏的调整 原帖地址:https://www.cnblogs.com/seanshao/p/5716543.html 修改 ...

  7. 博客园页面定制html代码,你要的博客园主题都有!!!

    基于最近很多小伙伴加我微信想要我的博客园主题,那我就把博客园主题整理一下,送给喜欢的小伙伴,园友们喜欢可以收藏,关注,博客园主题仅供参考,博主顺便再多说一句,虽然我可以分享给你们,但是我更愿意你们加我 ...

  8. 博客园添加鼠标粒子吸附特效

    本文从以下三个方面, 阐述在博客园添加鼠标粒子吸附特效: 一. 效果展示 二. 权限申请 三. 设置步骤 一. 效果展示 在博客园的页面, 出现鼠标粒子吸附的特效, 如图所示: 二. 权限申请 点击博 ...

  9. 设置博客园的背景图片,自定义样式以及导航目录

    无意间看到几个大神的博客园,人家的背景为啥是彩色的?为啥有动画效果?为啥能自定义功能?我递归懵逼的同时羡慕不已,于是找了几个文章整理了一下自己的博客园主页 前提 你需要开通设置里面的js权限,请求开通 ...

最新文章

  1. 清瘦的记录者: 一个比dbutils更小巧、好用的的持久化工具
  2. 5分钟带你读「大清」微积分!160多年前清朝数学家撰写文言文版高等数学
  3. golang copy函数
  4. Java虚拟机的Heap监狱
  5. 易语言动画框和动画物体通过代码载入外部图片数据不显示!
  6. CNN的几种经典模型
  7. oracle timestamp计算两分钟前_阿里数据库真的超过Oracle了么?
  8. python解压.tar.gz
  9. 如何将kafka中的数据快速导入Hadoop?
  10. BZOJ2199[Usaco2011 Jan] 奶牛议会
  11. Bitmap 图片说明
  12. input输入身份证验证
  13. stm32flash取数据_STM32学习笔记:读写内部Flash(介绍+附代码)
  14. python实现Instagram网络爬虫
  15. 简单的nodejs+socket.io给指定的人发送消息
  16. 怎样提高神马推广转换效率?
  17. l7809cv是什么管子_L7805CV稳压电路图 L7805CV引脚图封装参数大全
  18. 阿里云人脸识别C#调用示例参考
  19. 秦皇岛计算机编程大赛,关于举办第三届河北省大学生程序设计竞赛燕山大学选拔赛的通知...
  20. 使用Macbook远程Windows

热门文章

  1. java如何去除噪点,消除黑白图像中的噪点
  2. 超适合新手使用的教程:Python环境配置+Pycharm安装+扩展包安装(以Numpy+mkl为例)
  3. java 日期格式化 英文_Java SimpleDateFormat 中英文时间格式化转换
  4. Hibernate查询技术之HQL语句
  5. Rockland 艾美捷Foxp3抗体说明书
  6. python的网络请求库urllib、urllib2、urllib3、request的联系
  7. 云顶之弈两个传送门_云顶之弈入口不见了怎么回事?云顶之弈入口开放时间几点...
  8. Java:base64编码与解码和URL编码与解码
  9. 美国电影毕业生主题曲
  10. Suterusu对话Waves | 隐私, DeFi繁荣的关键