固定寬度的天氣主按鈕,滑鼠懸停時右側內容面板從左向右滑出(像抽屜),移開滑回隱藏,動畫流暢,類似騰訊微博側邊欄互動。
<div class="weather">
<div class="weather_main"><strong><a>深圳</a></strong></div>
<div class="alert">
<p>如果雲知道,多想涼風來做伴~</p>
<p><a>提醒好友</a></p>
</div>
</div>
<style>
.weather { width:500px; height:100px; margin:0 auto; position:relative; overflow:hidden; color:#fff; text-align:center; }
.weather_main { width:99px; border-right:1px solid #fff; float:left; background:#F03; position:relative; z-index:2; }
.weather_main strong { line-height:100px; }
.alert { width:400px; height:100px; position:absolute; left:-400px; top:0; background:#F03; }
</style>
$(function() {
$('.weather_main').hover(
function() { $('.alert').animate({ left: '100px' }, 1000); },
function() { $('.alert').animate({ left: '-400px' }, 1000); }
);
});
.animate({left: '100px'}, 1000):1 秒內從 left:-400px 滑至 left:100px(緊貼主按鈕右側)。hover(enter, leave):進入/離開分別觸發展開/收合。stop() 可防止快速進出導致動畫排隊(建議加上)。