js實現(xiàn)超酷的照片墻展示效果圖附源碼下載
這是一個超酷的照片墻展示效果,很多照片結合淡入淡出、旋轉(zhuǎn)、縮放、傾斜及3D效果,照片快速從左側切入,做旋轉(zhuǎn)3D效果,最后在照片墻上整齊排列,為用戶展示了超酷的照片墻展示效果。

HTML
本文結合實例給大家分享超酷的照片墻效果,該效果依賴jQuery和easing插件,因此首先載入這兩個文件。
<script src="jquery.min.js"></script> <script src="jquery.easing.1.3.js"></script>
接著,我們在需要展示照片墻的位置放置如下代碼:
<div class="grid"></div> <div class="animate">點擊看效果</div>
CSS
CSS定義了照片墻基本樣式,照片排列以及按鈕樣式。
.grid {
width: 600px; height: 300px; margin: 100px auto 50px auto;
perspective: 500px; /*For 3d*/
}
.grid img {width: 60px; height: 60px; display: block; float: left;}
.animate {
text-transform: uppercase;
background: rgb(0, 100, 0); color: white;
padding: 10px 20px; border-radius: 5px;
cursor: pointer;margin:10px auto;width:100px;text-align:center;
}
.animate:hover {background: rgb(0, 75, 0);}
JS
首先我們在頁面上動態(tài)載入50張照片,照片源來自網(wǎng)絡。
var images = "", count = 50;
for(var i = 1; i <= count; i++)
images += '<img src="http://thecodeplayer.com/u/uifaces/'+i+'.jpg" />';
$(".grid").append(images);
當點擊按鈕時,50張圖片做不同程度的變形縮放轉(zhuǎn)換淡出效果,因為要切入下一個照片墻了,當這些動作全部完成時,開始切入照片墻動畫效果,調(diào)用了storm()函數(shù)。
var d = 0; //延時
var ry, tz, s; //定義轉(zhuǎn)換參數(shù)
$(".animate").on("click", function(){
$("img").each(function(){
d = Math.random()*1000; //1ms to 1000ms delay
$(this).delay(d).animate({opacity: 0}, {
step: function(n){
s = 1-n; //scale - will animate from 0 to 1
$(this).css("transform", "scale("+s+")");
},
duration: 1000
})
}).promise().done(function(){
storm(); //淡出效果全部完成時調(diào)用
})
})
自定義函數(shù)storm()完成了將每張照片進行角度旋轉(zhuǎn)和Z軸位移動作,結合CSS3使得產(chǎn)生3D效果,然后調(diào)用easing實現(xiàn)緩沖效果,讓整個照片墻切入十分流暢,請看代碼:
function storm(){
$("img").each(function(){
d = Math.random()*1000;
$(this).delay(d).animate({opacity: 1}, {
step: function(n){
//rotating the images on the Y axis from 360deg to 0deg
ry = (1-n)*360;
//translating the images from 1000px to 0px
tz = (1-n)*1000;
//applying the transformation
$(this).css("transform", "rotateY("+ry+"deg) translateZ("+tz+"px)");
},
duration: 3000,
easing: 'easeOutQuint'
})
})
}
相關文章
JavaScript仿淘寶頁面圖片滾動加載及刷新回頂部的方法解析
這篇文章主要介紹了JavaScript仿淘寶頁面圖片滾動加載及刷新回頂部的方法解析,包括懶加載和onbeforeunload等要點的理解,需要的朋友可以參考下2016-05-05
js實現(xiàn)網(wǎng)頁倒計時、網(wǎng)站已運行時間功能的代碼3例
這篇文章主要介紹了js實現(xiàn)網(wǎng)頁倒計時、網(wǎng)站已運行時間功能的代碼3例,需要的朋友可以參考下2014-04-04
分享兩個手機訪問pc網(wǎng)站自動跳轉(zhuǎn)手機端網(wǎng)站代碼
這篇文章主要介紹了分享兩個手機訪問pc網(wǎng)站自動跳轉(zhuǎn)手機端網(wǎng)站代碼,需要的朋友可以參考下2015-01-01

