DIV CSS 佈局教程網

用 jQuery 打造遮罩層效果的導覽選單
編輯:JQuery特效代碼     

導覽列幾乎是每個網站必備的模組,當使用者在瀏覽網站時,如何讓導覽列在互動時更醒目,是設計上的重點。這時就可以善用遮罩層,透過明暗對比來凸顯使用者當前的操作位置。以下分享實作程式碼。

$(function() {
var $oe_menu= $('#oe_menu');
var $oe_menu_items= $oe_menu.children('li');
var $oe_overlay= $('#oe_overlay');
$oe_menu_items.bind('mouseenter',function(){
var $this = $(this);
$this.addClass('slided selected');
$this.children('div').css('z-index','9999').stop(true,true).slideDown(200,function(){
$oe_menu_items.not('.slided').children('div').hide();
$this.removeClass('slided');
});
}).bind('mouseleave',function(){
var $this = $(this);
$this.removeClass('selected').children('div').css('z-index','1');
});
$oe_menu.bind('mouseenter',function(){
var $this = $(this);
$oe_overlay.stop(true,true).fadeTo(200, 0.6);
$this.addClass('hovered');
}).bind('mouseleave',function(){
var $this = $(this);
$this.removeClass('hovered');
$oe_overlay.stop(true,true).fadeTo(200, 0);
$oe_menu_items.children('div').hide();
})
});

核心概念是:滑鼠移入選單時,用 fadeTo 把遮罩層淡入到 0.6 的透明度,讓背景變暗;移出時再淡出還原。同時搭配 slideDown 讓子選單滑展開,並用 z-index 確保展開的內容浮在上層,stop(true,true) 則避免動畫堆疊造成的閃爍。

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved