效果图

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. MySQL ubuntu启动

    service mysql start 启动 service mysql restart 重启 service mysql stop 停止 mysql -uroot -ppassword 登入mysq ...

  2. javascript content

    1. Chrome, Mozila, IE 2. jQuery, underscore, zepto 3. underscore 4. Backbone, AngularJS 5. RequireJS ...

  3. ArrayList的toArray

    ArrayList提供了一个将List转为数组的一个非常方便的方法toArray.toArray有两个重载的方法: 1.list.toArray(); 2.list.toArray(T[]  a); ...

  4. c++实现委托

    #include "stdafx.h" #include <iostream> #include <string> using namespace std; ...

  5. -_-#【Mac】MacVim

    MacVim安装与配置 Mac开发利器之程序员编辑器MacVim学习总结 Git时代的VIM不完全使用教程 zencoding-vim This repository has moved to htt ...

  6. 扩展KMP模板

    注意:需要用特殊符号隔开 1 struct ExKmp{ void Init(){ memset(f,,sizeof(f)); memset(r,,sizeof(r)); } void Get_Fai ...

  7. Codeforces 716B Complete the Word【模拟】 (Codeforces Round #372 (Div. 2))

    B. Complete the Word time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  8. 【数论】FOJ 2238 Daxia & Wzc's problem

    题目链接: http://acm.fzu.edu.cn/problem.php?pid=2238 题目大意: 已知等差数列A(0)的首项a和公差d,求出数列A(0)前n项和,得到新数列A(1);以此类 ...

  9. 编写一个单独的Web Service for Delphi7(步骤)

    1新建一个SOAP Server Application,在提示输入接口时输入MyHello,把所有文件保存在一个叫Ser的目录下,其中一个包含TWebModule1的文件保存为main.pas.在M ...

  10. 在mac中用终端来运行.c文件

    第一步:打开终端,位置在lauchpad中去找搜索. 第二步:建一个.c文件. 第三步: 在终端输入.c路径.用cd命令 第五步:cc -c +tab键.生成.O文件 第六步:cc +tab键.生成. ...