如何利用js模仿360開機(jī)的效果?很多人都不太了解,今天小編為了讓大家更加了解js模仿360開機(jī)效果的方法,所以給大家總結(jié)了以下內(nèi)容,一起往下看吧。
實(shí)現(xiàn)效果:
點(diǎn)擊關(guān)閉圖片按鈕先往下退出再往右退出。
實(shí)現(xiàn)步驟:
1、封裝運(yùn)動(dòng)函數(shù)
2、給圖片上的關(guān)閉設(shè)置一個(gè)盒子
3、給關(guān)閉盒子注冊(cè)點(diǎn)擊事件點(diǎn)擊后
4、下面圖片高度為0,設(shè)置一個(gè)緩動(dòng)動(dòng)畫
5、上面圖片寬度為0,設(shè)置一個(gè)緩動(dòng)動(dòng)畫
緩動(dòng)動(dòng)畫代碼(帶回調(diào)函數(shù)):`
function getStyle(obj,attr){ //兼容性寫法獲得樣式 if(window.getComputedStyle){ return window.getComputedStyle(obj, null)[attr]; }else{ return obj.currentStyle[attr]; } } function animate(obj, json, speed, callback){ clearInterval(obj.timer); obj.timer = setInterval(function(){ var flag = true; for(var attr in json){ var current = parseInt(getStyle(obj,attr)); var step = (json[attr] - current) / 10; step = step > 0 ? Math.ceil(step) : Math.floor(step); obj.style[attr] = current + step +'px'; if(current != json[attr]){ flag = false; } } if(flag){ clearInterval(obj.timer); if(callback && typeof callback == 'function'){ //驗(yàn)證callback是否傳遞,傳遞的話看是否是函數(shù)類型 callback(); } } },speed); }
開機(jī)圖片,的由兩個(gè)圖片中組成
<!DOCTYPE html> <html> <head> <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; } .box img{ vertical-align: top; } </style> <script type="text/javascript" src="函數(shù)封裝.js"></script> <script type="text/javascript"> function $(id){ return document.getElementById(id); } window.onload = function(){ var span = document.getElementsByTagName('span')[0]; var box = $('box'); var bottom = $('bt'); var top = $('hd'); span.onclick = function(){ var json = {"height": 0}; animate(bottom,json,20,function(){ animate(box,{"width":0},20); }); } } </script> </head> <body> <div id="box"> <span></span> <div id="hd"> <img src="images/t.jpg" alt=""/> </div> <div id="bt"> <img src="images/b.jpg" alt=""/> </div> </div> </body> </html>
效果如下:
以上就是如何利用js模仿360開機(jī)的效果的簡略介紹,當(dāng)然詳細(xì)使用上面的不同還得要大家自己使用過才領(lǐng)會(huì)。如果想了解更多,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道哦!
網(wǎng)站標(biāo)題:如何利用js模仿360開機(jī)的效果-創(chuàng)新互聯(lián)
文章URL:http://www.chinadenli.net/article24/dpjjce.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站營銷、App設(shè)計(jì)、標(biāo)簽優(yōu)化、網(wǎng)站導(dǎo)航、域名注冊(cè)、網(wǎng)站排名
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容