圖片相簿中,訪客往往希望能把縮圖放大看清楚。本文示範一款 jQuery 特效:點擊縮圖後會彈出大圖層,還能進一步放大檢視原圖、縮放以及關閉,操作相當直覺。
效果展示:
https://hovertree.com/texiao/jqimg/2/
效果圖:
下載:
https://hovertree.com/h/bjaf/jdaqepet.htm
相簿由一個容器 #hovertreephoto 與數張帶有 .test class 的縮圖組成:
<div id="hovertreephoto">
<img class="test" src="photo/1.jpg" alt="">
<img class="test" src="photo/2.jpg" alt="">
<img class="test" src="photo/3.jpg" alt="">
</div>引入 jQuery、插件腳本與樣式表後,只需一行呼叫即可為所有縮圖加上放大檢視功能:
<link href="https://hovertree.com/texiao/jqimg/2/css/style.css" rel="stylesheet" type="text/css" />
<script src="https://down.hovertree.com/jquery/jquery-1.12.3.min.js"></script>
<script src="https://hovertree.com/texiao/jqimg/2/js/jquey-bigic.js"></script>
<script>
$(function(){
$('#hovertreephoto img').bigic();
});
</script>bigic() 方法會自動為容器內的圖片綁定點擊事件,彈出的圖層支援放大為原圖、縮放與關閉。透過簡單的 CSS,還能把縮圖統一縮放為固定尺寸,讓相簿排列更整齊。