菜單ul類將頂部展開全寬,當懸停li類時它會觸發拖放內容打開。當鼠標仍然處於「ul」狀態時,我希望保持最後一次打開的內容不變,並且只有當鼠標完全離開菜單時纔會隱藏內容。 jsFiddle設置,blue bg字段是「ul」類,我希望當鼠標仍然存在時,最後一個內容保持打開狀態。如何讓jquery下拉菜單在懸停li類時打開
http://jsfiddle.net/R7aTq/150/
(function($){
$.fn.naviDropDown = function(options) {
//set up default options
var defaults = {
dropDownClass: 'dropdown', //the class name for your drop down
dropDownWidth: 'auto', //the default width of drop down elements
slideDownEasing: 'easeInOutCirc', //easing method for slideDown
slideUpEasing: 'easeInOutCirc', //easing method for slideUp
slideDownDuration: 500, //easing duration for slideDown
slideUpDuration: 500, //easing duration for slideUp
orientation: 'horizontal' //orientation - either 'horizontal' or 'vertical'
};
var opts = $.extend({}, defaults, options);
return this.each(function() {
var $this = $(this);
$this.find('.'+opts.dropDownClass).css('width', opts.dropDownWidth).css('display', 'none');
var buttonWidth = $this.find('.'+opts.dropDownClass).parent().width() + 'px';
var buttonHeight = $this.find('.'+opts.dropDownClass).parent().height() + 'px';
if(opts.orientation == 'horizontal') {
$this.find('.'+opts.dropDownClass).css('left', '0px').css('top', buttonHeight);
}
if(opts.orientation == 'vertical') {
$this.find('.'+opts.dropDownClass).css('left', buttonWidth).css('top', '0px');
}
$this.find('li').hoverIntent(getDropDown, hideDropDown);
});
function getDropDown(){
activeNav = $(this);
showDropDown();
}
function showDropDown(){
activeNav.find('.'+opts.dropDownClass).slideDown({duration:opts.slideDownDuration, easing:opts.slideDownEasing});
}
function hideDropDown(){
activeNav.find('.'+opts.dropDownClass).slideUp({duration:opts.slideUpDuration, easing:opts.slideUpEasing});//hides the current dropdown
}
};
})(jQuery);
可以完成,但不是微不足道的,不可能發生在這樣的局部情況的幫助論壇。必須刪除'hoverintent'並重寫單個鼠標事件和定時器,並使其跨瀏覽器兼容。建議親自動手 – charlietfl