javascript原生360 開機小動畫

來源:互聯網
上載者:User

標籤:log   20px   json   htm   com   meta   位置   技術   math   

<!DOCTYPE html><html><head lang="en">    <meta charset="UTF-8">    <title></title>    <style>        .box{            width: 322px;            position: fixed;            bottom:0;            right:0;        }        span{            position: absolute;            top:0;            right:0;            width:30px;            height: 20px;            cursor: pointer;        }    </style>    <script src="../jquery1.0.0.1.js"></script>    <script>        // window.onload = function () {        //     //需求:下面的盒子高度變為0,然後大盒子的寬在變為0.        //     var guanbi = document.getElementById("guanbi");        //     var box = guanbi.parentNode;        //     var b = document.getElementById("b");        //     guanbi.onclick = function () {        //         //下面的盒子高度變為0,然後大盒子的寬在變為0.        //         animate(b,{"height":0}, function () {        //             animate(box,{"width":0});        //         });        //     }        // }        //                 window.onload=function(){            var oClose=document.getElementById("guanbi");            var oBox=document.getElementsByTagName("div")[0];                        var oB=document.getElementById("b");            oClose.onclick=function(){                animate(oB,{"height":0},function(){                    animate(oBox,{"width":0});                });            }        }    </script></head><body>    <div class="box">        <span id="guanbi"></span>        <div class="hd" id="t">            <img src="images/t.jpg" alt=""/>        </div>        <div class="bd" id="b">            <img src="images/b.jpg" alt=""/>        </div>    </div></body></html>

引入原生Javascript

/** * Created by Lenovo on 2016/9/11. */function show(ele){    ele.style.display = "block";}/** * 擷取元素樣式相容寫法 * @param ele * @param attr * @returns {*} */function getStyle(ele,attr){    if(window.getComputedStyle){        return window.getComputedStyle(ele,null)[attr];    }    return ele.currentStyle[attr];}//參數變為3個function animate(ele,json,fn){    //先清定時器    clearInterval(ele.timer);    ele.timer = setInterval(function () {        //開閉原則        var bool = true;        //遍曆屬性和值,分別單獨處理json        //attr == k(鍵)    target == json[k](值)        for(var k in json){            //四部            var leader = parseInt(getStyle(ele,k)) || 0;            //1.擷取步長            var step = (json[k] - leader)/10;            //2.二次加工步長            step = step>0?Math.ceil(step):Math.floor(step);            leader = leader + step;            //3.賦值            ele.style[k] = leader + "px";            //4.清除定時器            //判斷: 目標值和當前值的差大於步長,就不能跳出迴圈            //不考慮小數的情況:目標位置和當前位置不相等,就不能清除清除定時器。            if(json[k] !== leader){                bool = false;            }        }        console.log(1);        //只有所有的屬性都到了指定位置,bool值才不會變成false;        if(bool){            clearInterval(ele.timer);            //所有程式執行完畢了,現在可以執行回呼函數了            //只有傳遞了回呼函數,才能執行            if(fn){                fn();            }        }    },1);}//擷取螢幕可視地區的寬高function client(){    if(window.innerHeight !== undefined){        return {            "width": window.innerWidth,            "height": window.innerHeight        }    }else if(document.compatMode === "CSS1Compat"){        return {            "width": document.documentElement.clientWidth,            "height": document.documentElement.clientHeight        }    }else{        return {            "width": document.body.clientWidth,            "height": document.body.clientHeight        }    }}

 

javascript原生360 開機小動畫

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.