效果图

html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>关键字球状效果</title>
<link rel="stylesheet" href="css/style.css" />
<script type="text/javascript" src="js/lrtk.js"></script>
</head>
<body>
<!-- 代码开始 -->
<div id="div1">
<a href="http://www.lanrentuku.com" target="_blank">起名取名</a> <a
href="http://www.lanrentuku.com" target="_blank">宣传策划</a> <a
href="http://www.lanrentuku.com" target="_blank">网游试玩</a> <a
href="http://www.lanrentuku.com" target="_blank">短信表白</a> <a
href="http://www.lanrentuku.com" target="_blank">卡片设计</a> <a
href="http://www.lanrentuku.com" target="_blank">网页设计</a> <a
href="http://www.lanrentuku.com" target="_blank">SEO优化</a> <a
href="http://www.lanrentuku.com" target="_blank">外语翻译</a> <a
href="http://www.lanrentuku.com" target="_blank">产品推广</a> <a
href="http://www.lanrentuku.com" target="_blank">网络营销</a> <a
href="http://www.lanrentuku.com" target="_blank">动漫设计</a> <a
href="http://www.lanrentuku.com" target="_blank">招聘求职</a> <a
href="http://www.lanrentuku.com" target="_blank">家居装修</a> <a
href="http://www.lanrentuku.com" target="_blank">影视创作</a> <a
href="http://www.lanrentuku.com" target="_blank">照片美化</a> <a
href="http://www.lanrentuku.com" target="_blank">产品设计</a> <a
href="http://www.lanrentuku.com" target="_blank">包装设计</a> <a
href="http://www.lanrentuku.com" target="_blank">Logo设计</a> <a
href="http://www.lanrentuku.com" target="_blank">海报设计</a> <a
href="http://www.lanrentuku.com" target="_blank">程序开发</a> <a
href="http://www.lanrentuku.com" target="_blank">网店推广</a> <a
href="http://www.lanrentuku.com" target="_blank">微博营销</a> <a
href="http://www.lanrentuku.com" target="_blank">网站开发</a> <a
href="http://www.lanrentuku.com" target="_blank">宣传品设计</a> <a
href="http://www.lanrentuku.com" target="_blank">配音配词</a> <a
href="http://www.lanrentuku.com" target="_blank">产品推广</a> <a
href="http://www.lanrentuku.com" target="_blank">网络营销</a> <a
href="http://www.lanrentuku.com" target="_blank">动漫设计</a> <a
href="http://www.lanrentuku.com" target="_blank">招聘求职</a> <a
href="http://www.lanrentuku.com" target="_blank">家居装修</a> <a
href="http://www.lanrentuku.com" target="_blank">影视创作</a> <a
href="http://www.lanrentuku.com" target="_blank">照片美化</a>
</div>
</body>
</html>

css

body{background:#09c;}
#div1{height:400px;width:450px; position:relative; margin:10px auto;}
#div1 a{position:absolute;top:0px;left:0px;color:#fff;font-weight:bold;padding:3px 6px;}
#div1 a:hover{border:1px solid #eee;background:#000;border-radius:5px;}

javascript

var radius = 150;
var dtr = Math.PI / 180;
var d = 300; var mcList = [];
var active = false;
var lasta = 1;
var lastb = 1;
var distr = true;
var tspeed = 2;
var size = 250; var mouseX = 0;
var mouseY = 0; var howElliptical = 1; var aA = null;
var oDiv = null; window.onload = function() {
var i = 0;
var oTag = null; oDiv = document.getElementById('div1'); aA = oDiv.getElementsByTagName('a'); for (i = 0; i < aA.length; i++) {
oTag = {}; oTag.offsetWidth = aA[i].offsetWidth;
oTag.offsetHeight = aA[i].offsetHeight; mcList.push(oTag);
} sineCosine(0, 0, 0); positionAll(); oDiv.onmouseover = function() {
active = true;
}; oDiv.onmouseout = function() {
active = false;
}; oDiv.onmousemove = function(ev) {
var oEvent = window.event || ev; mouseX = oEvent.clientX - (oDiv.offsetLeft + oDiv.offsetWidth / 2);
mouseY = oEvent.clientY - (oDiv.offsetTop + oDiv.offsetHeight / 2); mouseX /= 5;
mouseY /= 5;
}; setInterval(update, 30);
}; function update() {
var a;
var b; if (active) {
a = (-Math.min(Math.max(-mouseY, -size), size) / radius) * tspeed;
b = (Math.min(Math.max(-mouseX, -size), size) / radius) * tspeed;
} else {
a = lasta * 0.98;
b = lastb * 0.98;
} lasta = a;
lastb = b; if (Math.abs(a) <= 0.01 && Math.abs(b) <= 0.01) {
return;
} var c = 0;
sineCosine(a, b, c);
for (var j = 0; j < mcList.length; j++) {
var rx1 = mcList[j].cx;
var ry1 = mcList[j].cy * ca + mcList[j].cz * (-sa);
var rz1 = mcList[j].cy * sa + mcList[j].cz * ca; var rx2 = rx1 * cb + rz1 * sb;
var ry2 = ry1;
var rz2 = rx1 * (-sb) + rz1 * cb; var rx3 = rx2 * cc + ry2 * (-sc);
var ry3 = rx2 * sc + ry2 * cc;
var rz3 = rz2; mcList[j].cx = rx3;
mcList[j].cy = ry3;
mcList[j].cz = rz3; per = d / (d + rz3); mcList[j].x = (howElliptical * rx3 * per) - (howElliptical * 2);
mcList[j].y = ry3 * per;
mcList[j].scale = per;
mcList[j].alpha = per; mcList[j].alpha = (mcList[j].alpha - 0.6) * (10 / 6);
} doPosition();
depthSort();
} function depthSort() {
var i = 0;
var aTmp = []; for (i = 0; i < aA.length; i++) {
aTmp.push(aA[i]);
} aTmp.sort(function(vItem1, vItem2) {
if (vItem1.cz > vItem2.cz) {
return -1;
} else if (vItem1.cz < vItem2.cz) {
return 1;
} else {
return 0;
}
}); for (i = 0; i < aTmp.length; i++) {
aTmp[i].style.zIndex = i;
}
} function positionAll() {
var phi = 0;
var theta = 0;
var max = mcList.length;
var i = 0; var aTmp = [];
var oFragment = document.createDocumentFragment(); // 随机排序
for (i = 0; i < aA.length; i++) {
aTmp.push(aA[i]);
} aTmp.sort(function() {
return Math.random() < 0.5 ? 1 : -1;
}); for (i = 0; i < aTmp.length; i++) {
oFragment.appendChild(aTmp[i]);
} oDiv.appendChild(oFragment); for (var i = 1; i < max + 1; i++) {
if (distr) {
phi = Math.acos(-1 + (2 * i - 1) / max);
theta = Math.sqrt(max * Math.PI) * phi;
} else {
phi = Math.random() * (Math.PI);
theta = Math.random() * (2 * Math.PI);
}
// 坐标变换
mcList[i - 1].cx = radius * Math.cos(theta) * Math.sin(phi);
mcList[i - 1].cy = radius * Math.sin(theta) * Math.sin(phi);
mcList[i - 1].cz = radius * Math.cos(phi); aA[i - 1].style.left = mcList[i - 1].cx + oDiv.offsetWidth / 2
- mcList[i - 1].offsetWidth / 2 + 'px';
aA[i - 1].style.top = mcList[i - 1].cy + oDiv.offsetHeight / 2
- mcList[i - 1].offsetHeight / 2 + 'px';
}
} function doPosition() {
var l = oDiv.offsetWidth / 2;
var t = oDiv.offsetHeight / 2;
for (var i = 0; i < mcList.length; i++) {
aA[i].style.left = mcList[i].cx + l - mcList[i].offsetWidth / 2 + 'px';
aA[i].style.top = mcList[i].cy + t - mcList[i].offsetHeight / 2 + 'px'; aA[i].style.fontSize = Math.ceil(12 * mcList[i].scale / 2) + 8 + 'px'; aA[i].style.filter = "alpha(opacity=" + 100 * mcList[i].alpha + ")";
aA[i].style.opacity = mcList[i].alpha;
}
} function sineCosine(a, b, c) {
sa = Math.sin(a * dtr);
ca = Math.cos(a * dtr);
sb = Math.sin(b * dtr);
cb = Math.cos(b * dtr);
sc = Math.sin(c * dtr);
cc = Math.cos(c * dtr);
}

来源:懒人图库 原文地址

js 实现关键词球状旋转效果的更多相关文章

  1. js实现关键词高亮显示 正则匹配

    html 和ajax 部分就不写了,只需将需要匹配的文字传进去就可以了 比如匹配后台传回的字符串data.content中的关键词:直接调用: data.content = highLightKeyw ...

  2. Python-JS (JS介绍~JS的基础数据类型)

    目录一.JS语言介绍: 1.JS概念 2.JS组成 二.JS的三种存在位置(引入方式): 1.行间式: 2.内联式: 3.外联式: 三.JS出现的具体位置: 四.JS语法规范 五.JS中变量的定义 E ...

  3. PHP 结合 Boostrap 结合 js 实现学生列表删除编辑以及搜索功能(完结)

    这个自己的小项目要先告一段落了.可能还有许多bug.请见谅 删除学生功能 PHP: // 这里是通过前端代码HTML中的 url 传过来的,用 $_GET 来获取(相关HTML代码可以看一下到主页看一 ...

  4. JavaScipt的秘密花园

    对象使用和属性 JavaScript 中所有变量都可以当作对象使用,除了两个例外 null 和undefined. false.toString(); // 'false'[1, 2, 3].toSt ...

  5. JavaScript学习笔记(一)对象和属性

    对象属性的使用 JavaScript中的所有变量都可以当做对象使用,除了null和undefined. false.toString(); // 'false' [1, 2, 3].toString( ...

  6. JavaScript代码规范

    变量名:驼峰命名法(首单词小写,后面每个单词首字母大写) firstName = "John"; lastName = "Doe"; price = 19.90 ...

  7. 2018-01-15 History in Threads: 火狐插件实现浏览历史按主题显示(树)

    History in Threads似乎是唯一一个业余项目里有确认用户的. 大部分JavaScript源码(300+行)也用了中文命名. 插件功能很简单, 就是根据网页点击顺序生成树, 每个树可以认为 ...

  8. 十款不错的Hybrid App移动开发框架

    本文转载至http://www.pureasme.com/blog/2015/0419476.html ionic 是个高级的 HTML5 移动端应用框架,是个很漂亮的使用 HTML5 开发混合移动应 ...

  9. JavaScript 秘密花园——对象的使用和属性操作

    JavaScript 中所有变量都是对象,除了两个例外 null 和 undefined. false.toString(); // 'false' [1, 2, 3].toString(); // ...

随机推荐

  1. The Child and Sequence

    Codeforces Round #250 (Div. 1)D:http://codeforces.com/problemset/problem/438/D 题意:给你一个序列,然后有3种操作 1x ...

  2. codeforces C. Restore Graph

    题意:构造一个有n个顶点,每个点度不超过k,然后给出每一个点到达一个定点的最短距离d数组,然后构造出这样的一个图: 思路:排序之后,有两个距离为0的或者没有直接输出-1,然后用两个游动下表,后面的与前 ...

  3. Delphi 的各种错误信息(中英文)

    ******************************* * 编 译 错 误 信 息 * ******************************* ';' not allowed befo ...

  4. 【原生态跨平台:ASP.NET Core 1.0(非Mono)在 Ubuntu 14.04 服务器上一对一的配置实现-篇幅1】

    鸡冻人心的2016,微软高产年. build 2016后 各种干货层出不穷. 1 Win10 集成了bash  ,实现了纳德拉的成诺,Microsoft Love Linux!!! 2 跨平台  ,收 ...

  5. parted命令分区

    http://soft.chinabyte.com/os/447/12439447.shtml http://blog.163.com/warking_xp/blog/static/103910320 ...

  6. 【模拟】NCPC 2014 K Train passengers

    题目链接: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1797 题目大意: 有N个车站,火车一共可以坐M个人,每个车站下车Ai,上车Bi个人,在 ...

  7. 【模拟】FOJ 2244 Daxia want to buy house

    题目链接: http://acm.fzu.edu.cn/problem.php?pid=2244 题目大意: 每月还款额=贷款本金×[月利率×(1+月利率)^还款月数]÷[(1+月利率)^还款月数-1 ...

  8. 奔跑的xiaodao

    http://acm.hrbust.edu.cn/index.php?m=ProblemSet&a=showProblem&problem_id=2086 很明显的一个二分题目.因为要 ...

  9. supesite 标签语法

    http://blog.sina.com.cn/s/blog_a3c7706701018c8o.html

  10. android实现图片识别的几种方法

    实现android图像识别的几种方法 点击这里下载第一种代码 最近完成了毕业设计,论文名为基于图像识别的移动人口管理系统.编写过程中学到了几种图像识别的技术,先写下来与大家分享. 第一种,直接使用免费 ...