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

    js實(shí)現(xiàn)類似jquery里animate動(dòng)畫效果的方法
    來源:易賢網(wǎng) 閱讀:3891 次 日期:2015-04-13 14:05:51
    溫馨提示:易賢網(wǎng)小編為您整理了“js實(shí)現(xiàn)類似jquery里animate動(dòng)畫效果的方法”,方便廣大網(wǎng)友查閱!

    該實(shí)例可實(shí)現(xiàn)鼠標(biāo)移上,先寬度變化,再高度變化,最后透明度變化,鼠標(biāo)移出,再依次變回去的效果。

    要點(diǎn)一:

    startrun(obj,attr,target,fn)

    box.onmouseover = function(){

    startrun(box,"width",200,function(){

    startrun(box,"height",200,function(){

    startrun(box,"opacity","100")

    });

    });

    }

    如上面,函數(shù)也可以做為參數(shù)使用,就可以達(dá)到先執(zhí)行某個(gè)動(dòng)作,再執(zhí)行某個(gè)動(dòng)作的效果了。

    要點(diǎn)二:

    if(cur == target){

    clearInterval(obj.timer);

    if(fn){

    fn();

    }

    }

    當(dāng)運(yùn)動(dòng)到達(dá)目標(biāo)點(diǎn),關(guān)閉定時(shí)器,然后就可以執(zhí)行新的函數(shù)了。

    最后,上代碼:

    <!DOCTYPE html>

    <html>

    <head>

    <meta charset="gb2312" />

    <title>無標(biāo)題文檔</title>

    <style>

    <!--

    body{margin:0; padding:0; font:12px/1.5 arial;}

    #box{width:100px; height:100px; position:absolute;

    background:#06c; left:0;filter:alpha(opacity=30); opacity:0.3;}

    -->

    </style>

    <script>

    <!--

    function getstyle(obj,name){

    if(obj.currentStyle){

    return obj.currentStyle[name];

    }else{

    return getComputedStyle(obj,false)[name];

    }

    }

    window.onload = function(){

    var box = document.getElementById("box");

    box.onmouseover = function(){

    startrun(box,"width",200,function(){

    startrun(box,"height",200,function(){

    startrun(box,"opacity","100")

    });

    });

    }

    box.onmouseout = function(){

    startrun(box,"height",100,function(){

    startrun(box,"width",100,function(){

    startrun(box,"opacity","30");

    });

    });

    }

    }

    function startrun(obj,attr,target,fn){

    clearInterval(obj.timer);

    obj.timer = setInterval(function(){

    var cur = 0;

    if(attr == "opacity"){

    cur = Math.round(parseFloat(getstyle(obj,attr))*100);

    }else{

    cur = parseInt(getstyle(obj,attr));

    }

    var speed = (target-cur)/8;

    speed = speed>0?Math.ceil(speed):Math.floor(speed);

    if(cur == target){

    clearInterval(obj.timer);

    if(fn){

    fn();

    }

    }else{

    if(attr == "opacity"){

    obj.style.filter = "alpha(opacity="+(cur+speed)+")";

    obj.style.opacity = (cur+speed)/100;

    }else{

    obj.style[attr] = cur + speed + "px";

    }

    }

    },30)

    }

    //-->

    </script>

    </head>

    <body>

    <div id="box">

    </div>

    </body>

    </html>

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

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

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

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