我想超級魚呈現菜單,使每個菜單欄有一套CSS,將允許我給每個菜單列不同的CSS屬性。 I.E.不同的文字顏色,不同的背景顏色,懸停顏色。修改超級魚菜單jQuery插件
例如,菜單可能是
Home | About Us:Meet the Team:Why Hire Us | Contact Us:Social Media | Our Services
其中,「關於我們」有兩個子菜單項和「聯繫我們」有一個子菜單項。
我想給他們添加樣式,以便.imMenu-Primary1 ... imMenu-PrimaryN在每個主菜單項上,它是子項目。此外,我想附加到他們的每個孩子像這樣.imMenu-Childof-Primary1 .... imMenu-Childof-PrimaryN。或者類似的東西,可以讓我爲每個主菜單項目設置風格,並將其作爲一個組進行組合。
以下是我認爲相關的Superfish文件。
預先感謝您的時間和精力,
添
附:我正在使用Wordpress生成菜單,並且不能或者不知道如何在Wordpress中漫遊菜單結構來添加CSS。我注意到,雖然超級潛艇不會走菜單樹結構,我很確定可以使用JavaScript添加CSS屬性。這就是爲什麼我建議這樣做。但是,如果有更好的方法來做到這一點,我就會全神貫注。再次感謝。
;(function($){ // $ will refer to jQuery within this closure
$.fn.supersubs = function(options){
var opts = $.extend({}, $.fn.supersubs.defaults, options);
// return original object to support chaining
return this.each(function() {
// cache selections
var $$ = $(this);
// support metadata
var o = $.meta ? $.extend({}, opts, $$.data()) : opts;
// cache all ul elements and show them in preparation for measurements
$ULs = $$.find('ul').show();
// get the font size of menu.
// .css('fontSize') returns various results cross-browser, so measure an em dash instead
var fontsize = $('<li id="menu-fontsize">—</li>').css({
'padding' : 0,
'position' : 'absolute',
'top' : '-999em',
'width' : 'auto'
}).appendTo($$)[0].clientWidth; //clientWidth is faster than .width()
// remove em dash
$('#menu-fontsize').remove();
// loop through each ul in menu
$ULs.each(function(i) {
// cache this ul
var $ul = $(this);
// get all (li) children of this ul
var $LIs = $ul.children();
// get all anchor grand-children
var $As = $LIs.children('a');
// force content to one line and save current float property
var liFloat = $LIs.css('white-space','nowrap').css('float');
// remove width restrictions and floats so elements remain vertically stacked
$ul.add($LIs).add($As).css({
'float' : 'none',
'width' : 'auto'
});
// this ul will now be shrink-wrapped to longest li due to position:absolute
// so save its width as ems.
var emWidth = $ul[0].clientWidth/fontsize;
// add more width to ensure lines don't turn over at certain sizes in various browsers
emWidth += o.extraWidth;
// restrict to at least minWidth and at most maxWidth
if (emWidth > o.maxWidth) { emWidth = o.maxWidth; }
else if (emWidth < o.minWidth) { emWidth = o.minWidth; }
emWidth += 'em';
// set ul to width in ems
$ul.css('width',emWidth);
// restore li floats to avoid IE bugs
// set li width to full width of this ul
// revert white-space to normal
$LIs.css({
'float' : liFloat,
'width' : '100%',
'white-space' : 'normal'
})
// update offset position of descendant ul to reflect new width of parent.
// set it to 100% in case it isn't already set to this in the CSS
.each(function(){
var $childUl = $(this).children('ul');
var offsetDirection = $childUl.css('left') !== undefined ? 'left' : 'right';
$childUl.css(offsetDirection,'100%');
});
}).hide();
});
};
// expose defaults
$.fn.supersubs.defaults = {
minWidth : 9, // requires em unit.
maxWidth : 25, // requires em unit.
extraWidth : 0 // extra width can ensure lines don't sometimes turn over due to slight browser differences in how they round-off values
};
})(jQuery);
的說明我得到。不幸的是,我忘了提及我正在使用Wordpress,它正在爲我生成標記。這就是爲什麼我認爲它會使用supersubs .addCss,因爲它遍歷整個結構以獲得最大寬度。我無法把頭圍住它。我將編輯我的問題以反映我正在使用W Thank you.ordpress的事實。 – mpactMEDIA
如果你不能添加類,你總是可以使用諸如'li:nth-child(0)','li:nth-child:(1)'等選擇器。這不需要對標記進行任何修改。 – nullability
@nullabilty每次添加菜單項時都不需要更改代碼,但需要考慮子級深度的新級別?此外,它不允許我將單個主菜單項的子項作爲一個組與其他所有菜單項分開處理。例如,在上面的菜單中,第一個菜單項可能是紅色的,而子菜單項會是較淡的紅色。然後下一個菜單項可能是橙色,綠色,藍色,其各自的子菜單項是其頂級父母的色調。 – mpactMEDIA