jquery 菜单脚本中的淡入淡出样式

发布于 2024-10-22 04:35:27 字数 2206 浏览 2 评论 0原文

请参阅我已从 WEB 中的某个位置下载了此代码。但我不记得了。不管怎样,我想在鼠标悬停在菜单标题上时向菜单添加淡入淡出效果。当前脚本如下---

Jquery 代码----

            var timeout         = 500;
            var closetimer      = 0;
            var ddmenuitem      = 0;

            function menu_open()
            {   menu_canceltimer();
                menu_close();
                ddmenuitem = $(this).find('ul').eq(0).css('visibility', 'visible');}

            function menu_close()
            { if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');}

            function menu_timer()
            {   closetimer = window.setTimeout(menu_close, timeout);}

            function menu_canceltimer()
            {   if(closetimer)
                {   window.clearTimeout(closetimer);
                    closetimer = null;}}

            $(document).ready(function()
            {   $('#menu > li').bind('mouseover', menu_open);
                $('#menu > li').bind('mouseout',  menu_timer);});

            document.onclick = menu_close;

Html 代码 -----

<ul id="menu">
<li class="menu_head"><a href="#">JavaScript</a>
    <ul>
        <li><a href="#">Drop Down Menu</a></li>
        <li><a href="#">jQuery Plugin</a></li>
        <li><a href="#">Ajax Navigation</a></li>
    </ul>
</li>
<li  class="menu_head"><a href="#">Effect</a>
    <ul>
        <li><a href="#">Slide Effect</a></li>
        <li><a href="#">Fade Effect</a></li>
        <li><a href="#">Opacity Mode</a></li>
        <li><a href="#">Drop Shadow</a></li>
        <li><a href="#">Semitransparent</a></li>
    </ul>
</li>
<li class="menu_head"><a href="#">Navigation</a></li>
<li class="menu_head"><a href="#">HTML/CSS</a></li>
<li class="menu_head"><a href="#">Help</a></li>
</ul>

我尝试只添加 FadeIn()FadeOut() 效果,但它没有起作用。请帮帮我。

提前致谢!

See I have downloaded this code from somewhere in the WEB. But I don't remember. Anyway, I want to add fading effect to menu on mouse overing on of menu headers. The current script is as follows---

Jquery Code----

            var timeout         = 500;
            var closetimer      = 0;
            var ddmenuitem      = 0;

            function menu_open()
            {   menu_canceltimer();
                menu_close();
                ddmenuitem = $(this).find('ul').eq(0).css('visibility', 'visible');}

            function menu_close()
            { if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');}

            function menu_timer()
            {   closetimer = window.setTimeout(menu_close, timeout);}

            function menu_canceltimer()
            {   if(closetimer)
                {   window.clearTimeout(closetimer);
                    closetimer = null;}}

            $(document).ready(function()
            {   $('#menu > li').bind('mouseover', menu_open);
                $('#menu > li').bind('mouseout',  menu_timer);});

            document.onclick = menu_close;

Html Code -----

<ul id="menu">
<li class="menu_head"><a href="#">JavaScript</a>
    <ul>
        <li><a href="#">Drop Down Menu</a></li>
        <li><a href="#">jQuery Plugin</a></li>
        <li><a href="#">Ajax Navigation</a></li>
    </ul>
</li>
<li  class="menu_head"><a href="#">Effect</a>
    <ul>
        <li><a href="#">Slide Effect</a></li>
        <li><a href="#">Fade Effect</a></li>
        <li><a href="#">Opacity Mode</a></li>
        <li><a href="#">Drop Shadow</a></li>
        <li><a href="#">Semitransparent</a></li>
    </ul>
</li>
<li class="menu_head"><a href="#">Navigation</a></li>
<li class="menu_head"><a href="#">HTML/CSS</a></li>
<li class="menu_head"><a href="#">Help</a></li>
</ul>

I tried just adding FadeIn() and FadeOut() effect but it did not worked. Please help me out with.

Thanks in advance!

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

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

发布评论

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

评论(3

如果没有你 2024-10-29 04:35:28

http://jsfiddle.net/7cEbk/
我想这就是你想要的。

-迈克尔

        var timeout         = 500;
        var closetimer      = 0;
        var ddmenuitem      = 0;

        function menu_open()
        {   menu_canceltimer();
            menu_close();
            ddmenuitem = $(this).find('ul').eq(0).hide().fadeIn();}

        function menu_close()
        { if(ddmenuitem) ddmenuitem.show().fadeOut('fast');}

        function menu_timer()
        {   closetimer = window.setTimeout(menu_close, timeout);}

        function menu_canceltimer()
        {   if(closetimer)
            {   window.clearTimeout(closetimer);
                closetimer = null;}}

        $(document).ready(function()
        {   $('#menu > li').bind('mouseover', menu_open);
            $('#menu > li').bind('mouseout',  menu_timer);
        });

        document.onclick = menu_close;

http://jsfiddle.net/7cEbk/
I think this is what you want.

-michael

        var timeout         = 500;
        var closetimer      = 0;
        var ddmenuitem      = 0;

        function menu_open()
        {   menu_canceltimer();
            menu_close();
            ddmenuitem = $(this).find('ul').eq(0).hide().fadeIn();}

        function menu_close()
        { if(ddmenuitem) ddmenuitem.show().fadeOut('fast');}

        function menu_timer()
        {   closetimer = window.setTimeout(menu_close, timeout);}

        function menu_canceltimer()
        {   if(closetimer)
            {   window.clearTimeout(closetimer);
                closetimer = null;}}

        $(document).ready(function()
        {   $('#menu > li').bind('mouseover', menu_open);
            $('#menu > li').bind('mouseout',  menu_timer);
        });

        document.onclick = menu_close;
や三分注定 2024-10-29 04:35:28

嘿,我只是在 jsFiddle 中搞乱了这个......我认为问题是你在 menu_open() 函数中调用了 menu_close() 。这对 fadeIn() 和 fadeOut() 造成了严重破坏。

这可能不是您的最终解决方案,但它可能会让您朝着正确的方向前进。为了清楚起见,我拆开了链条,请随意重新连接它。

function menu_open() {
    menu_canceltimer();
    ddmenuitem = $(this).find('ul').eq(0);
    ddmenuitem.fadeIn('slow');
}

function menu_close() {
    if(ddmenuitem) {
        ddmenuitem.fadeOut('slow');
    }
}

Hey there, I was just messing around with this in jsFiddle... I think the problem was that you were calling menu_close() in your menu_open() function. This was causing havoc with fadeIn() and fadeOut().

This probably won't be your final solution, but it might get you going in the right direction. I broke apart the chaining for clarity, feel free to reconnect it.

function menu_open() {
    menu_canceltimer();
    ddmenuitem = $(this).find('ul').eq(0);
    ddmenuitem.fadeIn('slow');
}

function menu_close() {
    if(ddmenuitem) {
        ddmenuitem.fadeOut('slow');
    }
}
早乙女 2024-10-29 04:35:28

修改后的JS

var timeout = 500;
var closetimer = 0;
var ddmenuitem = 0;

function menu_open() {
    menu_canceltimer();
    menu_close();
    ddmenuitem = $(this).find('ul').eq(0).fadeIn('slow');
}

function menu_close()
{ if (ddmenuitem) ddmenuitem.fadeOut('slow'); }

function menu_timer()
{ closetimer = window.setTimeout(menu_close, timeout); }

function menu_canceltimer() {
    if (closetimer) {
        window.clearTimeout(closetimer);
        closetimer = null;
    } 
}

$(document).ready(function () {
    $('#menu > li').bind('mouseover', menu_open);
    $('#menu > li').bind('mouseout', menu_timer);
});

document.onclick = menu_close;

Modifed JS

var timeout = 500;
var closetimer = 0;
var ddmenuitem = 0;

function menu_open() {
    menu_canceltimer();
    menu_close();
    ddmenuitem = $(this).find('ul').eq(0).fadeIn('slow');
}

function menu_close()
{ if (ddmenuitem) ddmenuitem.fadeOut('slow'); }

function menu_timer()
{ closetimer = window.setTimeout(menu_close, timeout); }

function menu_canceltimer() {
    if (closetimer) {
        window.clearTimeout(closetimer);
        closetimer = null;
    } 
}

$(document).ready(function () {
    $('#menu > li').bind('mouseover', menu_open);
    $('#menu > li').bind('mouseout', menu_timer);
});

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