拿去白嫖吧:

<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="referrer" content="origin" />
<meta property="og:description"
content="你可能在很多博客中看到类似当鼠标移动上去的时候会出现线条吸附在鼠标周围的特效,鼠标离开的时候线条就自动散开。" />
<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>漂浮磁力线/鼠标吸铁石特效</title>
<script src="https://common.cnblogs.com/scripts/jquery-2.2.0.min.js"></script>
</head> <body>
<div id="page_end_html">
<!--磁力线放射-->
<script>
! function () {
function setNodeAttribute(node, attribute, value) {
return node.getAttribute(attribute) || value
}; function getEleByTagName(name) {
return document.getElementsByTagName(name)
}; function setDefaultAttribute() {
var elements = getEleByTagName("script"),
len = elements.length,
i = elements[len - 1];
return {
len: len,
zIndex: setNodeAttribute(i, "zIndex", -1),
opacity: setNodeAttribute(i, "opacity", .6),
color: setNodeAttribute(i, "color", "32,178,170"),
count: setNodeAttribute(i, "count", 150)
//<!-- opacity 参数设置的是透明程度,数字越小越透明; color 设置颜色; count 设置磁线的数量 -->
}
}; function initSize() {
canvasWidth = canvasEle.width = window.innerWidth || document.documentElement.clientWidth ||
document.body.clientWidth;
canvasHeight = canvasEle.height = window.innerHeight || document.documentElement.clientHeight ||
document.body.clientHeight
}; function start() {
ctx.clearRect(0, 0, canvasWidth, canvasHeight);
var node, e, curWidth, deltaX, deltaY, distance;
nodes.forEach(function (item, index) {
item.x += item.xa;
item.y += item.ya;
item.xa *= item.x > canvasWidth || item.x < 0 ? -1 : 1;
item.ya *= item.y > canvasHeight || item.y < 0 ? -1 : 1;
ctx.fillRect(item.x - .5, item.y - .5, 1, 1);
for (var e = index + 1; e < nodesIncludeMouse.length; e++) {
node = nodesIncludeMouse[e];
if (node.x !== null && node.y !== null) {
deltaX = item.x - node.x;
deltaY = item.y - node.y;
distance = deltaX * deltaX + deltaY * deltaY;
if (distance < node.max) {
if (node === mouse && distance >= node.max / 2) {
item.x -= .03 * deltaX;
item.y -= .03 * deltaY;
}
curWidth = (node.max - distance) / node.max;
ctx.beginPath();
ctx.lineWidth = curWidth / 2;
ctx.strokeStyle = "rgba(" + defaultAttr.color + "," + (curWidth + .2) + ")";
ctx.moveTo(item.x, item.y);
ctx.lineTo(node.x, node.y), ctx.stroke();
}
}
}
});
animate(start);
};
var canvasWidth, canvasHeight, nodesIncludeMouse, canvasEle = document.createElement("canvas"),
defaultAttr = setDefaultAttribute(),
ctx = canvasEle.getContext("2d"),
animate = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window
.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame ||
function (n) {
window.setTimeout(n, 1e3 / 45)
},
mathRandom = Math.random,
mouse = {
x: null,
y: null,
max: 2e4
};
canvasEle.id = "c_n" + defaultAttr.len;
canvasEle.style.cssText = "position:fixed;top:0;left:0;z-index:" + defaultAttr.zIndex + ";opacity:" +
defaultAttr.opacity;
getEleByTagName("body")[0].appendChild(canvasEle);
initSize();
window.onresize = initSize;
window.onmousemove = function (n) {
n = n || window.event, mouse.x = n.clientX, mouse.y = n.clientY
};
window.onmouseout = function () {
mouse.x = null, mouse.y = null
};
for (var nodes = [], f = 0; defaultAttr.count > f; f++) {
var h = mathRandom() * canvasWidth,
g = mathRandom() * canvasHeight,
v = 2 * mathRandom() - 1,
p = 2 * mathRandom() - 1;
nodes.push({
x: h, //x坐标
y: g, //y坐标
xa: v, //x速度
ya: p, //y速度
max: 6e3 //两点可连线的最大距离
});
}
nodesIncludeMouse = nodes.concat([mouse]);
setTimeout(function () {
start();
}, 100)
}();
</script> <script type="text/javascript">
/* 鼠标特效 */
var a_idx = 0;
jQuery(document).ready(function ($) {
$("body").click(function (e) {
var a = new Array("Laravel", "Wordpress", "公众号", "小程序", "ERP", "CRM", "帝国cms",
"Python", "Magento", "Dedecms", "Linux", "CI", "Thinkphp");
/* 可想而知,这里可以修改显示的字 */
var $i = $("<span />").text(a[a_idx]);
a_idx = (a_idx + 1) % a.length;
var x = e.pageX,
y = e.pageY;
$i.css({
"z-index": 999999999999999999999999999999999999999999999999999999999999999999999,
"top": y - 20,
"left": x,
"position": "absolute",
"font-weight": "bold",
"color": "#ff6651"
});
$("body").append($i);
$i.animate({
"top": y - 180,
"opacity": 0
},
1500,
function () {
$i.remove();
});
});
});
</script>
</div>
</body> </html>
 

js磁力线代码(非压缩,自己在压缩的版本上优化了代码,易于阅读)的更多相关文章

  1. "如何用70行Java代码实现深度神经网络算法" 的delphi版本

     http://blog.csdn.net/hustjoyboy/article/details/50721535 "如何用70行Java代码实现深度神经网络算法" 的delphi ...

  2. js分析 快速定位 js 代码, 还原被混淆压缩的 js 代码

    -1.目录 0.参考 1.页面表现 2. 慢镜头观察:低速网络请求 3. 从头到尾调试:Fiddler 拦截 index.html 并添加 debugger; 4. 快速定位 js 代码 5. 还原被 ...

  3. Grunt: 拼接代码,js丑化(压缩),css压缩,html压缩,观察文件,拷贝文件,删除文件,压缩文件

    准备工作 grunt 基于nodeJs所以 nodeJs需要的基础配置都需要安装 1.Grunt 安装 npm install -g grunt-cli 这是全局安装 2.在当前文件下npm init ...

  4. 前端自动化(三) 合并压缩css、压缩js、添加时间戳、打包上线操作

    前端自动化(三)   合并压缩css.压缩js.添加时间戳.打包上线操作 此文在前两篇基础上对比参考,会很方便理解 gulp.task("delete",function(){ r ...

  5. 使用gulp对js、css、img进行合并压缩

    1 概述 最新使用AngularJS框架做单页面项目,其中包括了很多库的和自已写的js.css.img文件,这些文件都不大,但是数量众多,导致web请求文件过多,一次性加载时比较慢.有尝试过使用异步加 ...

  6. require.js+backbone 使用r.js 在本地与生产环境 一键压缩的实现方式

    require.js+backbone 使用r.js 在本地与生产环境 一键压缩的实现方式 时间:2017-07-03 17:18:11      阅读:210      评论:0      收藏:0 ...

  7. node.js中使用imagemagick进行图片裁剪压缩

    node.js中使用imagemagick进行图片裁剪压缩 安装imagemagick sudo apt-get install imagemagick or wget http://www.imag ...

  8. Joomla - 优化(时区、google字体、压缩图片、压缩自定义代码)

    Joomla - 优化(时区.google字体.压缩图片.压缩自定义代码) 一.时区 发布文章是往往会发现发布时间和当前时间对不上,原因是 Joomla 用的是国际标准时间,和中国时区大约相差8小时, ...

  9. 两行代码搞定网站gzip压缩

    网站使用gzip压缩的好处就不用多说了吧,自行脑补,来说一下如何使用nodejs实现gzip压缩,只需要两行代码,so ease. 通过nodejs实现gzip 需要用到的模块 compression ...

随机推荐

  1. 【大白话系列】MySQL 学习总结 之 初步了解 MySQL Server 的 binlog 组件

    一.上节回顾 上节我们讲到,建议将 redo log 的刷盘策略设置为1:即提交事务时,强制将 redo log buffer 里的 redo log 刷入到磁盘后才算事务提交成功. 但是我们都知道, ...

  2. hadoop 日常使用记录

    1.Hadoop分布式文件系统(HDFS) HDFS基于GFS(Google File System),能够存储海量的数据,并且使用分布式网络客户端透明访问. HDFS中将文件拆分成特定大小的块结构( ...

  3. tensorflow variable scope 变量命名空间和变量共享

    import tensorflow as tf def f(): var = tf.Variable(initial_value=tf.random_normal(shape=[2])) return ...

  4. Codeforces_801

    A.直接暴力就行了,先把能组合的按线性组合掉,再枚举剩下相邻没用过的. #include<bits/stdc++.h> using namespace std; string s; ] = ...

  5. Educational Codeforces Round 76 (Rated for Div. 2) E. The Contest

    Educational Codeforces Round 76 (Rated for Div. 2) E. The Contest(dp+线段树) 题目链接 题意: 给定3个人互不相同的多个数字,可以 ...

  6. Loj 6002 最小路径覆盖(最大流)

    题意: 求不相交的最小路径覆盖 思路: 连边跑二分图,匹配一条边相当于缩了一条边,答案为n-maxflow 如果是求可以相交的最小路径覆盖的话,先用Floyd跑出可达矩阵,然后所有可达的点连边跑二分图 ...

  7. Flyway 的使用及Spring Boot集成Flyway

    一.简单介绍 Flyway 是一个开源.跨环境的数据库迁移工具,它强烈主张简单性和约定性而不是配置. Flyway 是一个便于多人开发对数据库管理的工具,将sql语句写入文件中,只需要在控制台输入指令 ...

  8. Springboot全局事务处理

    什么是全局事务 Spring Boot(Spring)事务是通过aop(aop相关术语:通知(Advice).连接点(Joinpoint).切入点(Pointcut).切面(Aspect).目标(Ta ...

  9. ELF和BIN的区别,资料整理

    https://www.cnblogs.com/fah936861121/articles/8143556.html 1.Bin Bin文件是最纯粹的二进制机器代码, 或者说是"顺序格式&q ...

  10. jsessionid與cookie關係的理解

    本地測試地址為http://localhost/TEST/login.jsf 當瀏覽器打開cookie時,瀏覽器第一次與服務器建立連接,會創建一個session,並生成一個id即jsessionid, ...