首頁  >  文章  >  web前端  >  jquery實現無限分級橫向導航選單的方法_jquery

jquery實現無限分級橫向導航選單的方法_jquery

WBOY
WBOY原創
2016-05-16 16:10:081517瀏覽

本文實例講述了jquery實現無限分級橫向導航選單的方法。分享給大家供大家參考。具體實作方法如下:

1. jquery外掛程式版本程式碼如下:

複製程式碼 程式碼如下:
(function($){
    $.fn.extend({
        droplinemenu: function(configs) {
            var configs = $.extend({               
                over: 200,
                out: 100,
                rightdown:'css/down.gif'
            },configs||{});
            this.find(">ul").addClass("dropmenu");
this.find("ul li:has(ul)").addClass('hasmenu').find(">a").append("jquery實現無限分級橫向導航選單的方法_jquery ");
            var currentobj;
            return $('li.hasmenu').hover(function(){                
                if ($.browser.msie) {//清除ie下產生的overflow:hidden
                    $(this).parent("ul").css({'overflow': 'visible'});
                }
                $(this).find(">ul").stop(true, true).css('top',$(this).height()).slideDown(configs.over);
            },function(){  
                $(this).find(">ul").stop(true, true).slideUp(configs.out);
            });
        }
    });
})(jQuery);

2. 樣式代碼
複製程式碼 程式碼如下:
* {margin:0;padding:0}
.droplinebar{
     position: absolute;
    z-index: 20;
    width: 700px;
}
.droplinebar ul.dropmenu {
position: relative;
}
.droplinebar ul{
width: 100%;
float: left;
font: bold 13px Arial;
background: #242c54 url​​(bluedefault.gif) center center repeat-x; /*default background of menu bar*/
}
.droplinebar ul li{
    float:left;
}
.droplinebar ul ul {
    width: 700px;
    display:none;
    z-index: 100;
    position:absolute;
    left:0;
    background: #303c76;
    zoom: 1;
}
.droplinebar ul li a{
    float: left;
    color: white;
    padding: 9px 11px;
    text-decoration: none;
    display:block;
}
.droplinebar ul li.hasmenu a img {border:none;margin-left:5px;}
.droplinebar ul li a:hover, .droplinebar ul li .current{ /*background of main menu bar links onMouseover*/
color: white;
background: transparent url(blueactive.gif) center center repeat-x;

/* Sub level menu links style */
.droplinebar ul li ul li a{
font: normal 13px Verdana;
padding: 6px;
padding-right: 8px;
margin: 0;
border-bottom: 1px solid navy;
}
.droplinebar ul li ul li a:hover{ /*sub menu links' background color onMouseover */
background: #242c54;
}

3. HTML程式碼如下
複製程式碼程式碼如下:




$(文檔).ready(function(){
    $("#mydroplinemenu").droplinemenu();
});
腳本>



4. 無插件版本代碼:
複製程式碼 程式碼如下:
$(document).ready(function(){
    var configs_over = 200,configs_out = 100;
$("#mydroplinemenu").find(">ul").addClass("dropmenu").find("li:has(ul)").addClass('hasmenu').find(">a"). append("jquery實現無限分級橫向導航選單的方法_jquery");
    $('.dropmenu li.hasmenu').hover(function(){             
        if ($.browser.msie) {//清除ie下產生的overflow:hidden
            $(this).parent("ul").css({'overflow': 'visible'});
        }
        $(this).find(">ul").stop(true, true).css('top',$(this).height()).slideDown(configs_over);
    },function(){  
        $(this).find(">ul").stop(true, true).slideUp(configs_out);
    });
});

希望本文所述對大家的jQuery程式設計有所幫助。

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn