默認以九宮格方式排列圖片,當鼠標懸停在圖片上時,會從上方下滑出一層半透明遮罩,同時伴隨文字介紹淡入,營造出層次豐富的懸停交互。
1、將 head 中的 css 樣式引入到你的網頁中;
2、將下面的 JS 代碼拷貝到網頁 body 結束前即可(js、圖片採用絕對路徑,不建議修改)。
$(function(){
$('.sgw_img dt').hover(function(){
$(this).children('.box').stop(true,true).delay(100).animate({'top':0,opacity:0.8},300);
},function(){
$(this).children('.box').stop(true,true).animate({'top':-482,opacity:0},200);
})
$('.sgw_img dd').hover(function(){
$(this).children('.box').stop(true,true).delay(100).animate({'top':0,opacity:0.8},300);
},function(){
$(this).children('.box').stop(true,true).animate({'top':-382,opacity:0},200);
})
})
核心在於用 animate 控制遮罩層的 top 與 opacity,配合 stop(true,true) 避免動畫堆疊,讓懸停進出更順滑。以上就是本文分享的全部內容,希望大家能夠喜歡。