将hoverIntent添加到jquery下拉菜单脚本中

发布于 2024-10-26 02:35:35 字数 447 浏览 7 评论 0原文

大家好,我想将hoverIntent事件添加到我的jquery下拉菜单顶部链接,但我不知道如何做到这一点,请帮助,下面是我从 http://www.dynamicdrive.com/style/csslibrary/item/jquery_multi_level_css_menu_2/ 我无法在这里发布代码,请在此处查看 http://www.dynamicdrive.com/cssexamples /media/jqueryslidemenu.js

Hi everybody i want to add hoverIntent 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

像你 2024-11-02 02:35:35

更新为使用动态驱动器的 jquery 滑动菜单:

请参阅此处的示例:http://jsfiddle.net/ vnvQn/

Dynamicdrive Slidemenu.js 中的

$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

将此:更改为:

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);

初始响应:

Soh Tonaka 的示例 Soh Tanaka 的大型下拉菜单

其 HTML 菜单结构如下:

<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>
        ...

使用 jquery,如下所示:

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);

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);
放手` 2024-11-02 02:35:35

我使用 doTimeout 插件

doTimeout Hover Intent Page

并编写与此类似的代码

  $("#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');
        });

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');
        });
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文