如何利用js模仿360開機的效果?很多人都不太了解,今天小編為了讓大家更加了解js模仿360開機效果的方法,所以給大家總結了以下內容,一起往下看吧。
創新互聯專注于網站建設,為客戶提供網站建設、做網站、網頁設計開發服務,多年建網站服務經驗,各類網站都可以開發,成都品牌網站建設,公司官網,公司展示網站,網站設計,建網站費用,建網站多少錢,價格優惠,收費合理。
.jpg)
實現效果:
點擊關閉圖片按鈕先往下退出再往右退出。
實現步驟:
1、封裝運動函數
2、給圖片上的關閉設置一個盒子
3、給關閉盒子注冊點擊事件點擊后
4、下面圖片高度為0,設置一個緩動動畫
5、上面圖片寬度為0,設置一個緩動動畫
緩動動畫代碼(帶回調函數):`
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是否傳遞,傳遞的話看是否是函數類型
callback();
}
}
},speed);
}開機圖片,的由兩個圖片中組成
<!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="函數封裝.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>效果如下:
.jpg)
以上就是如何利用js模仿360開機的效果的簡略介紹,當然詳細使用上面的不同還得要大家自己使用過才領會。如果想了解更多,歡迎關注創新互聯行業資訊頻道哦!
當前文章:如何利用js模仿360開機的效果
轉載源于:http://www.yijiale78.com/article16/pjdsdg.html
成都網站建設公司_創新互聯,為您提供云服務器、微信小程序、網站維護、網站策劃、微信公眾號、網站設計
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯