效果图

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. DataNode工作原理(四)

    DataNode的作用:提供真实文件数据的存储服务.以文件块进行存储. 文件块(block):最基本的存储单位.对文件内容而言,一个文件的长度大小是size,那么从文件的0偏移开始,按照固定的大小,顺 ...

  2. jquery的几个小例子

    <%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding= ...

  3. java和javascript获取word文档的书签位置对比

    1.javascript:把IE浏览器的activex都打开,使用如下网页,可以看到书签顺序和位置: ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 ...

  4. Unity NGUI 网络斗地主 -界面制作

    Unity NGUI 网络斗地主 -界面制作 源文件在群(63438968群共享!) @灰太龙 这一节说一下NGUI的界面摆放,并且教会大家使用NGUI的自适应功能! 在这里感谢@Gamer,是他给我 ...

  5. Sphnix创建文档

    http://www.ibm.com/developerworks/cn/opensource/os-sphinx-documentation/ Oracle实例名和服务名

  6. Effective c++ 第一章 让自己习惯C++

    条款 01:c++是一个语言联邦而不是一种单一的语言, 它包括: 1.C语言:没有模版.没有异常.没有重载…… 2.Object-Oriented C++:class.析构函数.构造函数.封装.继承. ...

  7. vtk 导出结果图片

    项目中需要将渲染结果导出为图片. (1)  一开始搜了vtk的方法,发现: http://blog.csdn.net/lbluekey/article/details/3346312 http://w ...

  8. [Locked] One Edit Distance

    One Edit Distance Given two strings S and T, determine if they are both one edit distance apart. 分析: ...

  9. 《University Calculus》-chape4-导数的应用-微分中值定理

    罗尔定理:如果函数f(x)在[a,b]上连续并且在(a,b)处处可微,并且有f(a) = f(b),则我们必然何以找到一个c∈(a,b),使得f’(c) = 0. 证明:我们从函数f(x)的最大值和最 ...

  10. python daemon化你的程序

    在之前的树莓派网关项目中遇到了这样一个问题,由于要把网关写的Server持续运行,尤其是要加电自动开启.发现ssh登录开启服务程序之后,当把pty退出时Server端自动断开了,这里想到的APUE中第 ...