js仿360開機效果
本文實例為大家分享了js仿360開機效果的具體代碼,供大家參考,具體內(nèi)容如下
實現(xiàn)效果:
1.點擊關(guān)閉圖片按鈕先往下退出再往右退出
實現(xiàn)步驟:
1.封裝運動函數(shù)
2.給圖片上的關(guān)閉設(shè)置一個盒子
3.給關(guān)閉盒子注冊點擊事件點擊后
4.下面圖片高度為0,設(shè)置一個緩動動畫
5.上面圖片寬度為0,設(shè)置一個緩動動畫
緩動動畫代碼(帶回調(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'){ //驗證callback是否傳遞,傳遞的話看是否是函數(shù)類型 callback(); } } },speed); }
開機圖片,的由兩個圖片中組成
<!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; } .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 class="box" id="box"> <span></span> <div class="hd" id="hd"> <img src="images/t.jpg" alt=""/> </div> <div class="bd" id="bt"> <img src="images/b.jpg" alt=""/> </div> </div> </body> </html>
效果:
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
JavaScript常見事件處理程序?qū)嵗偨Y(jié)
這篇文章主要介紹了JavaScript常見事件處理程序,結(jié)合實例形式總結(jié)分析了javascript HTML事件、DOM事件、IE事件等相關(guān)處理程序與操作技巧,需要的朋友可以參考下2019-01-01通過復(fù)制Table生成word和excel的javascript代碼
通過復(fù)制Table生成word和excel,個人感覺這個功能還是比較實用的,下面有個不錯的示例,希望對大家有所幫助2014-01-01