码迷,mamicode.com
首页 > 其他好文 > 详细

跟随鼠标的旋转文字效果

时间:2015-04-09 19:43:44      阅读:135      评论:0      收藏:0      [点我收藏+]

标签:

脚本说明:
    把如下代码加入<body>区域中
    <script language="JavaScript">
    <!--
    yourLogo=http://www.CsrCode.cn/;
    logoFont=Arial;
    logoSize=1; // 1-7 only! for larger font sizes alter logoWidth/Height accordingly!
    logoColor=811188;
    logoWidth=70;
    logoHeight=70;
    logoSpeed=0.03;
    //Nothing needs altering below!
    yourLogo=yourLogo.split(‘‘);
    L=yourLogo.length;
    Result="<font face="+logoFont+" size="+logoSize+" color="+logoColor+">";
    TrigSplit=360/L;
    br=(document.layers)?1:0;
    if (br){
    for (i=0; i < L; i++)
    document.write(<layer name="ns+i+" top=0 left=0 width=14 height=14">+Result+yourLogo[i]+</font></layer>);
    }
    else{
    document.write(<div id="outer" style="position:absolute;top:0px;left:0px"><div style="position:relative">);
    for (i=0; i < L; i++)
    document.write(<div id="ie" style="position:absolute;top:0px;left:0px;width:14px;height:14px">+Result+yourLogo[i]+</font></div>);
    document.write(</div></div>);
    }
    ypos=0;
    xpos=0;
    step=logoSpeed;
    currStep=0;
    Y=new Array();
    X=new Array();
    Yn=new Array();
    Xn=new Array();
    for (i=0; i < L; i++)
    {
    Yn[i]=0;
    Xn[i]=0;
    }
    (document.layers)?window.captureEvents(Event.MOUSEMOVE):0;
    function Mouse(evnt){
    ypos = (document.layers)?evnt.pageY:event.y;
    xpos = (document.layers)?evnt.pageX:event.x;
    }
    (document.layers)?window.onMouseMove=Mouse:document.onmousemove=Mouse;
    function animateLogo(){
    if (!br)outer.style.pixelTop=document.body.scrollTop;
    for (i=0; i < L; i++){
    var layer=(document.layers)?document.layers[ns+i]:ie[i].style;
    layer.top =Y[i]+logoHeight*Math.sin(currStep+i*TrigSplit*Math.PI/180);
    layer.left=X[i]+logoWidth*Math.cos(currStep+i*TrigSplit*Math.PI/180);
    }
    currStep-=step;
    }
    function Delay(){
    for (i=L; i >= 0; i--)
    {
    Y[i]=Yn[i]+=(ypos-Yn[i])*(0.1+i/L);
    X[i]=Xn[i]+=(xpos-Xn[i])*(0.1+i/L);
    }
    animateLogo();
    setTimeout(Delay(),20);
    }
    window.onload=Delay;
    // -->
    </script>

 

跟随鼠标的旋转文字效果

标签:

原文地址:http://www.cnblogs.com/youtianxia/p/4410283.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!