Change Font Size:

DHTML (web effects) tutorial examples - can control the rotation of the navigation of dynamic navigation

DHTML column collected some examples of DHTML Web effects, and can be used as learning javascript HTML DOM reference.

Actual results:


expand | Hidden | stop | Rotate | change direction of rotate
Code and a brief analysis:

<style type="text/css">
<!--
.style1 {
color: #0000FF;
font-size: 16px;
font-family: "ºÚÌå";
}
.style2 {
color: #FF0000;
font-size: 12px;
}
.style3 {
color: #663300;
font-size: 12px;
}
.spin
{
position : absolute;
visibility : hidden;
z-index : auto;
}
.spin a
{
font : 12px Verdana;
text-decoration : none;
}
.spin a:hover
{
text-decoration : underline overline;
}
-->
</style>

<script language="JavaScript1.2">
function getPageSize()
{
this.x = document.getElementsByTagName('html').item(0).clientWidth||document.getElementsByTagName('html').item(0).offsetWidth||document.body.offsetWidth||innerWidth
this.y = document.getElementsByTagName('html').item(0).clientHeight||document.getElementsByTagName('html').item(0).offsetHeight||document.body.offsetHeight||innerHeight
this.x2 = parseInt(this.x/2)||0
this.y2 = parseInt(this.y/2)||0
this.sx = document.body.scrollWidth||0
this.sy = document.body.scrollHeight||0
}
var pg

var pi = 3.1415

function spinMenu(cls,rad,eSpd,rSpd,dir,x,y,noCt,runEx)
{
pg = new getPageSize()
this.cls = cls
this.rad = rad
this.eSpd = eSpd
this.rSpd = rSpd
this.dir = dir ? 1 : -1
this.x = x<0 ? pg.x2 : x
this.y = y<0 ? pg.y2 : y
this.runEx = runEx||0
this.noCt = noCt||0
this.r = 0 // radius flux
this.ex = 0 // expand timeout
this.ct = 0 // contract timeout
this.rt = 1 // rotate timeout
this.vis = 0 // visibility
this.rNum = 0 // rotational flux
this.rSpd2 = 0 // rSpd holder
this.exDone = 0 // expand complete?
this.ctDone = 1 // contract complete?
this.toFig = 0
this.atX = 0
this.atY = 0
this.url = 0
this.target = 0
eval(this.obj + "=this")
this.items = new Array()
this.el = document.getElementsByTagName('div')
for(i=0;(this.el.item(i));i++)
{
if(this.el.item(i).className==this.cls)
{
this.el.item(i).onmouseover = new Function(this.obj+'.stop()')
this.el.item(i).onmouseout = new Function(this.obj+'.rotate()')
this.el.item(i).onclick = new Function(this.obj+'.contract()')
this.items[this.items.length] = this.el.item(i)
}
}
delete this.el
for(i=0;(this.items[i]);i++)
{
if(!this.items[i].childNodes.item(0).nodeValue)
{
this.items[i].childNodes.item(0).onmouseover = new Function('status=this.href;return true')
this.items[i].childNodes.item(0).onmouseout = new Function('status=\'\';return true')
this.items[i].childNodes.item(0).onclick = new Function(this.obj+'.setURL(this.href,this.target);return false')
this.items[i].childNodes.item(0).onfocus = new Function('this.blur()')
}
}
return this
}
spinMenu.prototype.init = function()
{
this.hide()
this.place()
this.expand()
}
spinMenu.prototype.rotate = function()
{
if(this.rSpd)
{
this.rNum += pi/(1000/this.rSpd)*this.dir
if(this.exDone)
{
this.place()
clearTimeout(this.rt)
this.rt = setTimeout(this.obj+'.rotate()',20)
}
}
}
spinMenu.prototype.stop = function()
{
clearTimeout(this.rt)
this.rt = 0
}
spinMenu.prototype.expand = function()
{
if(this.exDone!=1)
{
this.ctDone=0
if(!this.vis) this.show()
if(this.runEx) eval(this.runEx)
if(this.ct!=0)
{
clearTimeout(this.ct)
this.ct = 0
}
if(this.r<this.rad)
{
this.r += this.eSpd
if(this.rSpd2==0) this.rSpd2 = this.rSpd
this.rSpd = this.eSpd*3
this.rotate()
this.place()
this.ex = setTimeout(this.obj+'.expand()',10)
}
else
{
this.ex = 0
this.rSpd = this.rSpd2
this.rSpd2 = 0
this.ctDone = 0
this.exDone = 1
this.rotate()
}
}
}
spinMenu.prototype.contract = function()
{
if(this.ctDone!=1&&!this.noCt)
{
this.exDone = 0
if(this.ex!=0)
{
clearTimeout(this.ex)
this.ex = 0
}
if(this.r>0)
{
this.r -= this.eSpd
if(this.rSpd2==0) this.rSpd2 = this.rSpd
this.rSpd = this.eSpd
this.rotate()
this.place()
this.ct = setTimeout(this.obj+'.contract()',10)
}
else
{
this.rSpd = this.rSpd2
this.rSpd2 = 0
this.rNum = 0
this.stop()
this.hide()
this.exDone = 0
this.ctDone = 1
this.goURL()
}
}
else this.goURL()
}
spinMenu.prototype.place = function()
{
for(i=0;(this.items[i]);i++)
{
this.atPt(i)
this.items[i].style.left = this.atX-(this.items[i].offsetWidth/2)+'px'
this.items[i].style.top = this.atY-(this.items[i].offsetHeight/2)+'px'
}
}
spinMenu.prototype.atPt = function(pt)
{
this.toFig = pi/(this.items.length/2)*(pt+this.rNum)
this.atX = parseInt(Math.cos(this.toFig)*this.r+this.x)
this.atY = parseInt(Math.sin(this.toFig)*this.r+this.y)
}
spinMenu.prototype.show = function()
{
for(i=0;(this.items[i]);i++)
{
this.items[i].style.display = 'block'
this.items[i].style.visibility = 'visible'
this.vis = 1
}
}
spinMenu.prototype.hide = function()
{
for(i=0;(this.items[i]);i++)
{
this.items[i].style.visibility = 'hidden'
this.items[i].style.display = 'none'
this.vis = 0
}
}
spinMenu.prototype.changeDir = function()
{
this.dir = this.dir==1 ? -1 : 1
}
spinMenu.prototype.setURL = function(url,target)
{
this.url = url
this.target = target
}
spinMenu.prototype.goURL = function()
{
if(this.url)
{
if(!this.target)
if(document.getElementsByTagName('base').length) this.target = document.getElementsByTagName('base').item(0).target
if(this.target)
{
if(this.target=='_blank') open(this.url)
else if(this.target=='_parent') parent.location = this.url
else if(this.target=='_top') top.location = this.url
else if(this.target.indexOf('_')<0)
{
if(eval('parent.'+this.target)) eval('parent.'+this.target+'.document.location=this.url')
else if(eval('top.'+this.target)) eval('top.'+this.target+'.document.location=this.url')
else open(this.url,this.target)
}
else location = this.url
}
else location = this.url
this.url = 0
}
}

</script>
<script language="JavaScript1.2" type="text/javascript">
function centerIt()
{
pg = new getPageSize()
menu.x = pg.x2-10
menu.y = pg.y2
}
function initSpinMenu()
{
menu = new spinMenu(
'spin', // className
90, // radius
10, // expand/contract speed
3, // rotational speed
1, // direction (cw=1,ccw=0)
-100, // origin x
-1, // origin y
0, // stay expanded?
0 // run before expand
)
menu.init()
}
onload=initSpinMenu
onresize=centerIt
</script>

<div align="right"><a href="javascript:menu.expand()" target="_self" >expand</a> | <a href="javascript:menu.contract()" target="_self" >Hidden</a> | <a href="javascript:menu.stop()" target="_self" >stop</a> | <a href="javascript:menu.rotate()" target="_self" >Rotate</a> | <a href="javascript:menu.changeDir()" target="_self" >change direction of rotate</a></div>
<div style="visibility: visible; display: block; left: 436px; top: 288px;" class="spin"><a href="http://www.nt22.com/" >NT22</a></div>
<div style="visibility: visible; display: block; left: 520px; top: 280px;" class="spin"><a href="http://www.nt22.com/" >NT22</a></div>
<div style="visibility: visible; display: block; left: 581px; top: 335px;" class="spin"><a href="http://www.nt22.com/" >NT22</a></div>
<div style="visibility: visible; display: block; left: 560px; top: 413px;" class="spin"><a href="http://www.nt22.com/" >NT22</a></div>
<div style="visibility: visible; display: block; left: 499px; top: 454px;" class="spin"><a href="http://www.nt22.com/" >NT22</a></div>
<div style="visibility: visible; display: block; left: 426px; top: 428px;" class="spin"><a href="http://www.nt22.com/" >NT22</a></div>
<div style="visibility: visible; display: block; left: 412px; top: 354px;" class="spin"><a href="http://www.nt22.com/" >NT22</a></div>