午夜国产狂喷潮在线观看|国产AⅤ精品一区二区久久|中文字幕AV中文字幕|国产看片高清在线

    js實(shí)現(xiàn)宇宙星空背景效果的方法
    來源:易賢網(wǎng) 閱讀:1175 次 日期:2015-03-06 10:37:42
    溫馨提示:易賢網(wǎng)小編為您整理了“js實(shí)現(xiàn)宇宙星空背景效果的方法”,方便廣大網(wǎng)友查閱!

    這篇文章主要介紹了js實(shí)現(xiàn)宇宙星空背景效果的方法,實(shí)例分析了javascript中動(dòng)畫效果的實(shí)現(xiàn)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下

    本文實(shí)例講述了js實(shí)現(xiàn)宇宙星空背景效果的方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:

    代碼如下:

    <!DOCTYPE html PUBLIC "-//W3C//h2D XHTML 1.0 Transitional//EN" "">

    <html xmlns="">

    <head>

    <TITLE>宇宙星空背景效果,Js特效</TITLE>

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

    <style type="text/css">

    .star {

    position:absolute;

    layer-background-color:white;

    visibility:visible;

    top:-50px;

    width:50px;

    height:50px;

    font-size:1px;

    background-color:white;

    }

    .60pt{font-size:60pt;color:#ff66cc;}

    </style>

    <SCRIPT LANGUAGE="JavaScript">

    <!--

    var starnum = 75; // 星星的數(shù)目

    var isNS = (document.layers);

    var _all = (isNS)? '' : 'all.';

    var _style = (isNS) ? '' : '.style';

    var xoffset, yoffset, w_x, w_y, tmpx, tmpy, scrlx, scrly;

    function getstartpos(obj) { //定義星星移動(dòng)的起始位置

    obj.deltay = Math.floor(Math.random() * 12); //用隨機(jī)函數(shù)決定

    obj.deltax = Math.floor(Math.random() * 12);

    obj.xdir = (Math.floor(Math.random() * 2) == 1) ? '+' : '-';

    obj.ydir = (Math.floor(Math.random() * 2) == 1) ? '+' : '-';

    obj.counter = 1;

    if (isNS) {

    obj.clip.width = 1;

    obj.clip.height = 1;

    obj.moveTo(xoffset+pageXOffset, yoffset+pageYOffset);

    } else {

    obj.width = 1;

    obj.height = 1;

    obj.pixelTop = yoffset+document.body.scrollTop;

    obj.pixelLeft = xoffset+document.body.scrollLeft;

    }

    }

    function movestar(starN) //移動(dòng)星星的位置

    {

    tmpx = starN.deltax*starN.counter+starN.counter;

    tmpy = starN.deltay*starN.counter+starN.counter;

    if (isNS) {

    starN.clip.width = starN.counter / 3;

    starN.clip.height = starN.counter / 3;

    scrlx = pageXOffset;

    scrly = pageYOffset;

    if ((starN.left+tmpx >= w_x+scrlx) || (starN.top+tmpy >= w_y+scrly) || (starN.left-tmpx <= scrlx) || (starN.top-tmpy <= scrly)) {

    getstartpos(starN);

    } else {

    eval('starN.moveBy('+starN.xdir+tmpx+', '+starN.ydir+tmpy+')');

    }

    } else {

    starN.width = starN.counter/3;

    starN.height = starN.counter/3;

    scrlx = document.body.scrollLeft;

    scrly = document.body.scrollTop;

    if ((starN.pixelLeft+tmpx >= w_x+scrlx)||(starN.pixelTop+tmpy >= w_y+scrly) || (starN.pixelLeft-tmpx <= scrlx)||(starN.pixelTop-tmpy <= scrly)) {

    getstartpos(starN);

    } else {

    eval('starN.pixelTop'+starN.ydir+'=tmpy');

    eval('starN.pixelLeft'+starN.xdir+'=tmpx');

    }

    }

    starN.counter++;

    }

    function animate() //讓所有的星星動(dòng)起來

    {

    for(i=1; i <= starnum; i++) {

    movestar(eval('star'+i));

    }

    setTimeout('animate()', 100);

    }

    function findwindowparams() { //定義星星移動(dòng)的起始位置

    w_x = (isNS) ? window.innerWidth : document.body.clientWidth;

    w_y = (isNS) ? window.innerHeight : document.body.clientHeight;

    xoffset = w_x / 2;

    yoffset = w_y / 2;

    for (i = 1; i <= starnum; i++) {

    getstartpos(eval('star'+i));

    }

    }

    function resizeNS() {

    setTimeout('document.location.reload()', 400);

    }

    (isNS) ? window.onresize = resizeNS : window.onresize = findwindowparams;

    window.onload = new Function("findwindowparams(); animate();");

    -->

    </script>

    </HEAD>

    <BODY>

    <body bgcolor=#999999>

    <SCRIPT LANGUAGE="JavaScript">

    <!--

    for (i = 1; i <= starnum; i++) { //給星星定義層

    document.writeln('<div id="star'+i+'" class="star"></div>');

    eval('var star'+i+'=document.'+_all+'star'+i+_style);

    }

    -->

    </script>

    <p><center>

    <font class=60pt><br>飛翔在<br>宇宙的星空中<br></font>

    </center><p>

    </body>

    </html>

    運(yùn)行效果如下圖所示:

    名單

    希望本文所述對(duì)大家的javascript程序設(shè)計(jì)有所幫助。

    更多信息請(qǐng)查看IT技術(shù)專欄

    更多信息請(qǐng)查看腳本欄目
    易賢網(wǎng)手機(jī)網(wǎng)站地址:js實(shí)現(xiàn)宇宙星空背景效果的方法
    由于各方面情況的不斷調(diào)整與變化,易賢網(wǎng)提供的所有考試信息和咨詢回復(fù)僅供參考,敬請(qǐng)考生以權(quán)威部門公布的正式信息和咨詢?yōu)闇?zhǔn)!

    2025國考·省考課程試聽報(bào)名

    • 報(bào)班類型
    • 姓名
    • 手機(jī)號(hào)
    • 驗(yàn)證碼
    關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡(jiǎn)要咨詢 | 簡(jiǎn)要咨詢須知 | 新媒體/短視頻平臺(tái) | 手機(jī)站點(diǎn) | 投訴建議
    工業(yè)和信息化部備案號(hào):滇ICP備2023014141號(hào)-1 云南省教育廳備案號(hào):云教ICP備0901021 滇公網(wǎng)安備53010202001879號(hào) 人力資源服務(wù)許可證:(云)人服證字(2023)第0102001523號(hào)
    云南網(wǎng)警備案專用圖標(biāo)
    聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關(guān)注公眾號(hào):hfpxwx
    咨詢QQ:1093837350(9:00—18:00)版權(quán)所有:易賢網(wǎng)
    云南網(wǎng)警報(bào)警專用圖標(biāo)