Kênh 360 Công Nghệ Kênh 360 Công Nghệ

jQuery Navigation

Sử dụng jQuery để hiển thị menu dropdown đơn giản. show-submenu-on-hover-menu.

Mã HTML:

<ul id="menu">
<li>Sub 1
<ul>
<li>test 1</li>
<li>test 2</li>
<li>test 3</li>
<li>test 4</li>
</ul>
</li>
<li>Sub 2
<ul>
<li>test 1</li>
<li>test 2</li>
<li>test 3</li>
<li>test 4</li>
</ul>
</li>
</ul>

Code:

$(document).ready(function() {
var toggle = function(direction, display) {
return function() {
var self = this;
var ul = $("ul", this);
if( ul.css("display") == display && !self["block" + direction] ) {
self["block" + direction] = true;
ul["slide" + direction]("slow", function() {
self["block" + direction] = false;
});
}
};
}
$("li.menu").hover(toggle("Down", "none"), toggle("Up", "block"));
$("li.menu ul").hide();
});


Ít hiệu ứng hơn: chỉ show/hide:

$(document).ready(function() {

$("#menu li ul").hide();

$("#menu li").hover(
function () {
$(this).children("ul").show();
},function(){
$(this).children("ul").hide();
});//hover

});// document ready

In the previous example, please use js to hide the menu (the first line) if your menu requires js. If some one doesn't have js turned on they can still get to your content. Also note you can change the show/hide to any old jQuery effect and use "slow" and "fast" to animate it.

Source: jquery.com


Lần cập nhật cuối ( Thứ ba, 28 Tháng 2 2012 16:39 )  

Kênh 360 công nghệ

  • Nổi bật
  • Tin mới
  • Game mới
  • PrestaShop Guide
  • PrestaShop

Có thể bạn quan tâm

Download nhiều nhất

11/12
Download PES 2011 - FIFA 11
693
18/12
binkw32 dll
175
18/12
TeamViewerQS
49
English French German Japanese Korean