开发者

Add hoverIntent to jquery dropdown menu script

Hi everybody i want to add hoverIntent开发者_C百科 event to my jquery dropdown menu top links but i don't know how i do this please help below is my jquery code i got from http://www.dynamicdrive.com/style/csslibrary/item/jquery_multi_level_css_menu_2/ i am unable to post code here please checkout here http://www.dynamicdrive.com/cssexamples/media/jqueryslidemenu.js


UPDATED to use dynamic drive's jquery slide menu:

see example here: http://jsfiddle.net/vnvQn/

within the dynamicdrive slidemenu.js change this:

$curobj.hover(
                function(e) {
                    var $targetul = $(this).children("ul:eq(0)")
                    this._offsets = {
                        left: $(this).offset().left,
                        top: $(this).offset().top
                    }
                    var menuleft = this.istopheader ? 0 : this._dimensions.w
                    menuleft = (this._offsets.left + menuleft + this._dimensions.subulw > $(window).width()) ? (this.istopheader ? -this._dimensions.subulw + this._dimensions.w : -this._dimensions.w) : menuleft
                    if ($targetul.queue().length <= 1) //if 1 or less queued animations
                    $targetul.css({
                        left: menuleft + "px",
                        width: this._dimensions.subulw + 'px'
                    }).slideDown(jqueryslidemenu.animateduration.over)
                }, function(e) {
                    var $targetul = $(this).children("ul:eq(0)")
                    $targetul.slideUp(jqueryslidemenu.animateduration.out)
                }) //end hover

to this:

var hoverOver = function(e) {
    var $targetul = $(this).children("ul:eq(0)")
    this._offsets = {
        left: $(this).offset().left,
        top: $(this).offset().top
    }
    var menuleft = this.istopheader ? 0 : this._dimensions.w
    menuleft = (this._offsets.left + menuleft + this._dimensions.subulw > $(window).width()) ? (this.istopheader ? -this._dimensions.subulw + this._dimensions.w : -this._dimensions.w) : menuleft
    if ($targetul.queue().length <= 1) //if 1 or less queued animations
        $targetul.css({
            left: menuleft + "px",
            width: this._dimensions.subulw + 'px'
        }).slideDown(jqueryslidemenu.animateduration.over)
}
var hoverOut = function(e) {
    var $targetul = $(this).children("ul:eq(0)")
    $targetul.slideUp(jqueryslidemenu.animateduration.out)
} //end hover

var config = {    
    over: hoverOver, // function = onMouseOver callback (REQUIRED)    
    timeout: 500, // number = milliseconds delay before onMouseOut    
    out: hoverOut // function = onMouseOut callback (REQUIRED)    
};

$curobj.hoverIntent(config);

INITIAL RESPONSE:

example from Soh Tonaka's Mega Dropdown Menu by Soh Tanaka

with an HTML menu structure like:

<ul id="topnav"> 
        <li> 
            <a href="#" class="home">Home</a> 
        </li> 
        <li> 
            <a href="#" class="products">Products</a> 
            <div class="sub"> 
                <ul> 
                    <li><h2><a href="#">Desktop</a></h2></li> 
                    <li><a href="#">Navigation Link</a></li> 
                    <li><a href="#">Navigation Link</a></li> 
                    <li><a href="#">Navigation Link</a></li> 
                    <li><a href="#">Navigation Link</a></li> 
                    <li><a href="#">Navigation Link</a></li> 
                    <li><a href="#">Navigation Link</a></li> 
                    <li><a href="#">Navigation Link</a></li> 
                </ul> 
            </div>
        ...

use jquery like:

function megaHoverOver(){
        $(this).find(".sub").stop().fadeTo('fast', 1).show();

        //Calculate width of all ul's
        (function($) { 
            jQuery.fn.calcSubWidth = function() {
                rowWidth = 0;
                //Calculate row
                $(this).find("ul").each(function() {                    
                    rowWidth += $(this).width(); 
                }); 
            };
        })(jQuery); 

        if ( $(this).find(".row").length > 0 ) { //If row exists...
            var biggestRow = 0; 
            //Calculate each row
            $(this).find(".row").each(function() {                             
                $(this).calcSubWidth();
                //Find biggest row
                if(rowWidth > biggestRow) {
                    biggestRow = rowWidth;
                }
            });
            //Set width
            $(this).find(".sub").css({'width' :biggestRow});
            $(this).find(".row:last").css({'margin':'0'});

        } else { //If row does not exist...

            $(this).calcSubWidth();
            //Set Width
            $(this).find(".sub").css({'width' : rowWidth});

        }
    }

    function megaHoverOut(){ 
      $(this).find(".sub").stop().fadeTo('fast', 0, function() {
          $(this).hide(); 
      });
    }


    var config = {    
         sensitivity: 2, // number = sensitivity threshold (must be 1 or higher)    
         interval: 100, // number = milliseconds for onMouseOver polling interval    
         over: megaHoverOver, // function = onMouseOver callback (REQUIRED)    
         timeout: 500, // number = milliseconds delay before onMouseOut    
         out: megaHoverOut // function = onMouseOut callback (REQUIRED)    
    };

    $("ul#topnav li .sub").css({'opacity':'0'});
    $("ul#topnav li").hoverIntent(config);


I use the doTimeout plugin

doTimeout Hover Intent Page

And write the code similar to this

  $("#writer").find('.note, .task').hover(function () {
            $(this).find('.listed').stop(true, true).doTimeout('listed', 250, 'slideDown', 'fast', 'easeInOutCubic');
        }, function(){
            $(this).find('.listed').stop(true, true).doTimeout('listed', 250, 'slideUp', 'fast', 'easeInOutCubic');
        });
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜